我正在使用asp.net MVC 5,目前我有两个上下文,当我在Azure中部署我的应用程序时,它给我带来了问题,因为我使用了存储库模式,所以我想将它合并到一个DataContext。
这是我在Identity Models类中的Applicationcontext
public class DataContext : IdentityDbContext<ApplicationUser>
{
public DataContext()
: base("SurgeryConn")
{
}
}
这是我的DataContext
public class DataContext:IdentityDbContext,IDbContext {
public DataContext()
: base("SurgeryConn")
{
}
//#region Properties
public DbSet<Supplier.Supplier> Supplier { get; set; }
public DbSet<Dispensary.Dispensary> Dispensary { get; set; }
public DbSet<Biochemistry> Biochemistry { get; set; }
//#endregion
public new IDbSet<TEntity> Set<TEntity>() where TEntity : class
{
return base.Set<TEntity>();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
答案 0 :(得分:0)
将DbSets移动到第一个上下文,如果您使用存储库模式,您可能希望将IN Context放在第一个上下文中,如下所示:
public class DataContext : IdentityDbContext<ApplicationUser>,IDbContext
{
public DataContext()
: base("SurgeryConn")
{
}
public DbSet<Supplier.Supplier> Supplier { get; set; }
public DbSet<Dispensary.Dispensary> Dispensary { get; set; }
public DbSet<Biochemistry> Biochemistry { get; set; }
public new IDbSet<TEntity> Set<TEntity>() where TEntity : class
{
return base.Set<TEntity>();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
}