【发布时间】:2020-06-04 12:06:32
【问题描述】:
我需要在 ASP.NET Core 中创建一个数据库并使用身份,并且我需要使用 UseInMemoryDatabase 但是当我尝试添加迁移时,我得到了这个错误:
无法创建“DortajContext”类型的对象。有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
这是我的开始:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<DortajContext>(options => options.UseInMemoryDatabase(databaseName: "DortajDistance"));
services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<DortajContext>();
services.AddControllers();
}
这是我的上下文:
public class DortajContext : IdentityDbContext<User, Role, int>
{
public DortajContext(DbContextOptions<DortajContext> options)
: base(options)
{
}
public DbSet<UserDistanceHistory> UserDistanceHistories { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ApplyConfigurationsFromAssembly(typeof(IType).Assembly);
}
}
我该如何解决这个问题?
【问题讨论】:
标签: c# asp.net database asp.net-core