DbContext inheritance database error

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)
    {
        // base.OnModelCreating(modelBuilder);
        // TODO configure relations here!
        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
{
    /// <summary>
    ///     The date of load report has been created
    /// </summary>
    public virtual DateTime Created { get; set; }

    /// <summary>
    ///     The project manager
    /// </summary>
    public User ProjectManager { get; set; }

    /// <summary>
    ///     The Id of project manager
    /// </summary>
    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? (, )? .

!

+4
1

Source: https://habr.com/ru/post/1524294/


All Articles