小编der*_*rus的帖子

IDesignTimeDbContextFactory[TContext] 违反了

我目前正在使用这个快速入门示例,并且在尝试让它工作时遇到了绝对的噩梦。由于遇到无穷无尽的异常,我已经放弃了首先开发数据库,​​而是希望从实体生成表,这不是我让事情工作的首选方式。

这样做我似乎不太走运......

我目前反对这个例外:

PM> dotnet ef 数据库更新 CustomerDbContext System.ArgumentException: GenericArguments[0], 'IdentityServerWithAspIdAndEF.Migrations.CustomerDbContext', on 'Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory1[TContext]' violates the constraint of type 'TContext'. ---> System.TypeLoadException: GenericArguments[0], 'IdentityServerWithAspIdAndEF.Migrations.CustomerDbContext', on 'Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory1[TContext]' 违反了类型参数 'TContext' 的约束。在 System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type) 在 System.RuntimeTypeHandle.Instantiate(Type[] inst) 在 System.RuntimeType.MakeGenericType(Type[] 实例化) ---内部结束异常堆栈跟踪 --- 在 System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e) 在 System.RuntimeType.MakeGenericType(Type[] 实例化) 在 Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextFactory(Type contextType) 在 Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes() 在 Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations。

对我来说,这与“错误,有一个错误”一样具有描述性……我采用了原始快速入门并进行了以下修改。

Startup.ConfigureServices 就是现在:

public void ConfigureServices(IServiceCollection services)
{
    string connectionString = Configuration.GetConnectionString("DefaultConnection");
    var migrationsAssembly = …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core identityserver4

6
推荐指数
1
解决办法
5593
查看次数