Entity framework 为什么我的所有模型类都会添加到我';m使用多个数据上下文类?

Entity framework 为什么我的所有模型类都会添加到我';m使用多个数据上下文类?,entity-framework,entity-framework-6,entity-framework-mapping,Entity Framework,Entity Framework 6,Entity Framework Mapping,具有多个数据上下文的Entity Framework 6代码优先迁移 注意:这是我关于堆栈溢出的第一篇文章,如果我需要提供更多细节,请告诉我 仅供参考:我已经阅读了以下文章: 我也在尝试做类似的事情。我的问题围绕Configuration.cs文件中生成的CreateTable方法展开 我有29个模型类,我正在尝试设置4个不同的数据上下文 在我的第一个数据上下文RulingRequestContext中,我有29个模型类中的11个: public class RulingRequestCont

具有多个数据上下文的Entity Framework 6代码优先迁移

注意:这是我关于堆栈溢出的第一篇文章,如果我需要提供更多细节,请告诉我

仅供参考:我已经阅读了以下文章:

我也在尝试做类似的事情。我的问题围绕Configuration.cs文件中生成的CreateTable方法展开

我有29个模型类,我正在尝试设置4个不同的数据上下文

在我的第一个数据上下文RulingRequestContext中,我有29个模型类中的11个:

public class RulingRequestContext : BaseContext<RulingRequestContext>
{
    public DbSet<RulingRequest> RulingRequests { get; set; }
    public DbSet<Agency> Agencies { get; set; }
    public DbSet<RulingRequestGroup> RulingRequestGroups { get; set; }
    public DbSet<RulingRequestOverallOutcome> RulingRequestOverallOutcomes { get; set; }
    public DbSet<RulingRequestType> RulingRequestTypes { get; set; }
    public DbSet<RulingRequestResult> RulingRequestResults { get; set; }
    public DbSet<Issue> Issues { get; set; }
    public DbSet<Decision> Decisions { get; set; }
    public DbSet<RulingRequestRoutingInformation> RulingRequestRoutingInformations { get; set; }
    public DbSet<Staff> Staffs { get; set; }
    public DbSet<StatusOfRulingRequest> StatusOfRulingRequests { get; set; }
问题:

(1) 是否所有29个模型类都因为关系/虚拟属性而添加到RulingRequest的Configuration.cs?例如,由于我的所有4个数据上下文类都有:public virtual Agency{get;set;},所有这些模型类都被添加到我的RulingRequestContext.cs类的Configuration.cs文件中

(2) 假设我的初始数据上下文类(RulingRequestContext)及其Configuration.cs类按预期工作,我是否应该注释掉其他3个Configuration.cs类中的所有CreateTable代码

(3) 或者我应该注释掉RulingRequestContext中未显示为DBSet属性的所有模型类的CreateTable代码吗?然后对我的其他3个DataContext类执行相同的操作


谢谢你花时间阅读这篇文章!请让我知道,如果有什么我可以做或不做,使我的职位在未来更好

是的,它正在抓取相关实体。您的链接谈到从其他上下文中注释掉表“在运行update命令之前,注释掉为Users表生成的代码,如上所示。因为Users表已经由第一次DbContext迁移创建。”

(1) enable-migrations -ContextTypeName <DbContext-Name-with-Namespaces> -MigrationsDirectory:<Migrations-Directory-Name>
(2) Add-Migration -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> <Migrations-Name>
(3) Update-Database -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> -Verbose
public class RulingRequest
{
    public RulingRequest()
    {
        this.RulingRequestResults = new HashSet<RulingRequestResult>();
        this.RulingRequestRoutingInformations = new HashSet<RulingRequestRoutingInformation>();
    }

    [DisplayName("Ruling Request ID")]
    public int RulingRequestID { get; set; }
    [DisplayName("Employee ID Number")]
    public string EmployeeIDNumber { get; set; }
    [DisplayName("Case Group")]
    public string RulingRequestGroupID { get; set; }
    [DisplayName("Type")]
    public Nullable<int> RulingRequestTypeID { get; set; }
    [DisplayName("First Name")]
    public string FirstName { get; set; }
    [DisplayName("Last Name")]
    public string LastName { get; set; }
    public string MI { get; set; }
    public string Suffix { get; set; }
    public string Address { get; set; }
    [DisplayName("Address 2")]
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public Nullable<int> Zip { get; set; }
    [DisplayName("Home Phone")]
    public string HomePhone { get; set; }
    [DisplayName("Work Phone")]
    public string WorkPhone { get; set; }
    public string Email { get; set; }
    [DisplayName("Agency")]
    public string AgencyNumber { get; set; }
    [DisplayName("Date Received")]
    public Nullable<System.DateTime> DateReceived { get; set; }
    [DisplayName("Grievance Initiation Date")]
    public Nullable<System.DateTime> GrievanceInitiationDate { get; set; }
    [DisplayName("Decision Date")]
    public Nullable<System.DateTime> DecisionDate { get; set; }
    [DisplayName("Re-Activation Date")]
    public Nullable<System.DateTime> ReActivationDate { get; set; }
    [DisplayName("Overall Outcome")]
    public Nullable<int> RulingRequestOverallOutcomeID { get; set; }
    [ScaffoldColumn(false)]
    public string CreatedBy { get; set; }
    [ScaffoldColumn(false)]
    public Nullable<System.DateTime> CreatedDatetime { get; set; }
    [ScaffoldColumn(false)]
    public string UpdatedBy { get; set; }
    [ScaffoldColumn(false)]
    public Nullable<System.DateTime> UpdatedDatetime { get; set; }

    public virtual Agency Agency { get; set; }
    public virtual RulingRequestGroup RulingRequestGroup { get; set; }
    public virtual RulingRequestOverallOutcome RulingRequestOverallOutcome { get; set; }
    public virtual RulingRequestType RulingRequestType { get; set; }
    public virtual ICollection<RulingRequestResult> RulingRequestResults { get; set; }
    public virtual ICollection<RulingRequestRoutingInformation> RulingRequestRoutingInformations { get; set; }

}
public virtual Agency Agency { get; set; }