我用 VS 2015 ctp 创建了一个 web 启动器应用程序,我想添加一个内存存储来做一些测试,但是当我尝试读取数据时,我收到了这条消息
数据存储“SqlServerDataStore”“InMemoryDataStore”可用。只能将上下文配置为使用单个数据存储。在设置服务时,通过覆盖 DbContext 类或 AddDbContext 方法中的 OnConfiguring 来配置数据存储。
如何创建第二个数据存储?ConfigureService
现在我在方法中有这一行
AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<ApplicationDbContext>()
.AddInMemoryStore()
.AddDbContext<WorkModel>( options => { options.UseInMemoryStore(persist: true); });
编辑:看起来情况尚不清楚。我有身份 sql server dbcontext,我想添加第二个 dbcontext,完全分开,我想在内存中运行。我正在寻找如何配置两个不同的 dbcontext,在这种情况下使用两个不同的数据存储。
第一个是 Identity ApplicationDbContext,另一个是这样的:
public class WorkModel : DbContext
{
public DbSet<Cliente> Clienti { get; set; }
public DbSet<Commessa> Commesse { get; set; }
protected override void OnModelCreating(ModelBuilder builder) {
builder.Entity<Cliente>().Key(cli => cli.ClienteId);
builder.Entity<Commessa>().Key(cli => cli.CommessaId);
}
}
或者您喜欢的任何自定义 dbcontext