我一直在尝试修复一个项目,以便它具有 IdentityServer4 的数据库脚本。我被告知要跑步
dotnet ef migrations add InitialIdentityServerMigration -c PersistedGrantDbContext
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时,我收到一个错误:
dotnet:找不到与命令“dotnet-ef”匹配的可执行文件
所以我遵循了一些资源来获取 dotnet-ef
我安装了一些 nuget 软件包:
但在所有这些之后我仍然收到相同的错误消息。
还有其他方法获取 Identity4 DB 的脚本吗?
c# entity-framework identityserver4 entity-framework-migrations
我的NET Core 3.1应用程序[models,dbcontext,application]都在自己的程序集中。我正在尝试为应用程序发出迁移。我不断收到此错误:
$ dotnet ef migrations add InitialCreate --project DataAccess
Run Code Online (Sandbox Code Playgroud)
MSBUILD:错误MSB1009:项目文件不存在。开关:DataAccess 无法检索项目元数据。确保它是基于 MSBuild 的 .NET Core 项目。如果使用自定义 BaseIntermediateOutputPath 或 MSBuildProjectExtensionsPath 值,请使用 --msbuildprojectextensionspath 选项。
目前的结构
*root
-App (.NET Core 3.1)
-DataAccess (.NET Standard 2.1) (Contains the DBContext)
-Models (.NET Standard 2.1) (contains models)
Run Code Online (Sandbox Code Playgroud)
我还尝试为迁移创建一个单独的程序集,并在我的App:
services.AddDbContext<[some DBContext]>(x => x.UseSqlServer([some string],x=>x.MigrationsAssembly("Migrations")));
Run Code Online (Sandbox Code Playgroud)
尝试过的结构
*root
-App
-Migrations (.NET Standard 2.1)
-DataAccess (.NET Standard 2.1)
-Models (.NET Standard 2.1)
Run Code Online (Sandbox Code Playgroud)
我不明白应该如何完成此操作。我希望能够进行迁移,理想情况下我希望将它们保留在自己的程序集中。目前我根本无法执行它们。
PS
我也尝试将其添加到我的Appcsproj 文件中:
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
Run Code Online (Sandbox Code Playgroud) 如果您熟悉生产代码,您总是会遇到需要在服务中请求/处理任何内容之前调用的逻辑。
我个人将它包装成这样的东西并从DI框架调用它:
public interface IMigrator
{
Task UpdateAsync();
}
Run Code Online (Sandbox Code Playgroud)
例如:
我目前对 Web API 框架不太精通,需要知道应该将该逻辑放在哪里?在Startup.Configure?合适吗?如果需要(比如说 10 分钟),结果会怎样?
需要您的建议:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services
.AddControllers();
services.Register(new CoreModule(), new DataModule());
}
// This method gets called by the …Run Code Online (Sandbox Code Playgroud) c# iis-express docker asp.net-core-webapi entity-framework-migrations
当我尝试在 ASP.NET Core 3.1 MVC 项目中创建迁移时,出现此错误 - 我需要帮助
Build started...
Build succeeded.
You must install or update .NET to run this application.
App: /Users/remzi/.dotnet/tools/.store/dotnet-ef/6.0.7/dotnet-ef/6.0.7/tools/net6.0/any/tools/netcoreapp2.0/any/ef.dll
Architecture: arm64
Framework: 'Microsoft.AspNetCore.App', version '3.1.0' (arm64)
.NET location: /usr/local/share/dotnet/
The following frameworks were found:
6.0.7 at [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=arm64&rid=osx.12-arm64
Run Code Online (Sandbox Code Playgroud) asp.net-core-mvc .net-core asp.net-core entity-framework-migrations
我删除了服务器资源管理器上的一个表及其模型,现在当我尝试更新数据库时,它说
无法删除表 dbo.Images,因为它不存在或您没有权限
我现在无法更新数据库并添加其他表,我不再想要该表。请帮忙!
我需要进行“全文索引”,但我使用的是 ef core 2.1 代码第一次迁移,但完整索引在核心中没有一流的支持。
我如何编写自己的迁移,以便在应用其他生成的迁移时应用?
entity-framework ef-code-first entity-framework-core entity-framework-migrations
我有点眼花缭乱;我正在使用 dotnet core (2.1) EF 进行迁移。当我仅根据上下文创建第一个迁移时,实际上看起来一切正常。
所以我有一个类似的上下文:
public class DataContext : IdentityDbContext<User, IdentityRole<Guid>, Guid>
{
public virtual DbSet<Country> Countries { get; set; }
public virtual DbSet<CountryUser> CountryUsers { get; set; }
//..more stuff
public DataContext(DbContextOptions options) : base(options)
{ }
}
Run Code Online (Sandbox Code Playgroud)
所以在创建迁移后它想添加:
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
Name = table.Column<string>(maxLength: 256, nullable:
//etc. etc. Removed rest of migrations.
Run Code Online (Sandbox Code Playgroud)
我以为一切都很好。
然后我开始关注下面的文章; 如何在 EF Core 2.1.0 中为管理员用户做种?
在设置HasData和播种数据库后,创建了一个新的迁移,它创建了一个新的迁移,它想要删除AspNetRoles表并创建为新表IdentityRole。我刚刚删除了数据库并尝试再次执行此操作,现在它只想在播种时插入数据。但我无法弄清楚我改变了什么,甚至更好,为什么它想要删除并创建不同的表。
有人可以解释一下它何时要创建 …
c# entity-framework-core .net-core entity-framework-migrations
My .Net Core version is 3.0.100-preview6-012264. You can ask me why I use the preview version. The main reason is useful work with GRPC (scaffolding for this). Now I would like to use entity framework in my project. I have the following .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protos\dashboard.proto" GrpcServices="Server" Generator="MSBuild:Compile" />
<Protobuf Include="Protos\users.proto" GrpcServices="Client" Generator="MSBuild:Compile" />
<Protobuf Include="Protos\anal.proto" GrpcServices="Client" Generator="MSBuild:Compile" />
<Content Include="@(Protobuf)" />
<None Remove="@(Protobuf)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DimaRabbitLogger" Version="1.3.3" />
<PackageReference Include="Grpc.AspNetCore.Server" …Run Code Online (Sandbox Code Playgroud) entity-framework-core entity-framework-migrations .net-core-3.0
我有以下课程:
public class Quiz
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string UserToken { get; set; }
public List<JoinQuizAndArea> AreasOfQuizzes { get; set; }
public List<QuizQuestion> Questions { get; set; }
}
public class QuizQuestion
{
public int ListRanking { get; set; }
public string Question { get; set; }
public string Answer1 { get; set; }
public string Answer2 { get; set; } …Run Code Online (Sandbox Code Playgroud) c# ef-code-first asp.net-core entity-framework-migrations ef-core-3.0
我正在尝试为我的Ticket班级搭建一个剃刀页面集,当实体框架尝试创建数据库时出现错误:
我的理解是,如果您有一个属性“Id”,它将使用它,并且如果您设置 [Key] 注释,它将专门告诉 Entity Framework 使用该属性。这两样东西我都有,那怎么办?
c# entity-framework-core ef-code-first-mapping entity-framework-migrations asp.net-core-scaffolding
entity-framework-migrations ×10
c# ×6
.net-core ×2
asp.net-core ×2
docker ×1
ef-core-3.0 ×1
iis-express ×1
msbuild ×1
sql ×1