We use the first EntityFramework code. I want to implement DbContext inheritance as:
public class AgileDbContextBase : DbContext
{
public DbSet<Account> Accounts { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new AccountEntityConfiguration())
.Add(new UserEntityConfiguration());
}
}
and
public class LoadContext : AgileDbContextBase
{
#region Public Properties
public DbSet<ProjectLoadEstimate> ProjectLoadEstimates { get; set; }
public DbSet<OccupationType> OccupationTypes { get; set; }
public DbSet<LoadReport> LoadReports { get; set; }
#endregion
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new ProjectLoadEstimateConfiguration())
.Add(new OccupationTypeEntityConfiguration())
.Add(new LoadReportEntityConfiguration());
}
}
one of the objects uses the other, which is in AgileDbContextBasecontext, here it is:
public class LoadReport : BaseEntity
{
public virtual DateTime Created { get; set; }
public User ProjectManager { get; set; }
public int ProjectManagerId { get; set; }
}
both contexts use automatic migrations. The problem is that when I try to update, the database on the LoadContextPackageManager says that
There is already an object in the database called Accounts.
, , . ?
, LoadContext , DbSet < > in LoadContext?
(, )?
.
!