C# 如何在实体框架迁移中排除实体及其属性?

C# 如何在实体框架迁移中排除实体及其属性?,c#,entity-framework,entity-framework-6,entity-framework-migrations,C#,Entity Framework,Entity Framework 6,Entity Framework Migrations,假设我有这个模型: // In Accounting.dll public class Invoice { public int Number{ get; set; } public Company { get; set; } } public AccountingDbContext : DbContext { // ... public DbSet<Invoice> Invoices { get; set; } } 公司是通过基础设施迁移创建的

假设我有这个模型:

// In Accounting.dll
public class Invoice
{
    public int Number{ get; set; }
    public Company { get; set; }
}

public AccountingDbContext : DbContext
{
    // ...

    public DbSet<Invoice> Invoices { get; set; }
}
公司
是通过
基础设施
迁移创建的。但是在
Accounting
项目中,它还发现公司是一个新事物,需要为其创建一个表

问题:在搭建迁移时,如何在
会计
中设置迁移,使
公司
不受影响


我尝试了
modelBuilder.Entity.Ignore()
。这不是一个好的解决方案,因为整个实体框架忽略了它。我只想让迁移忽略它。

您可以编辑迁移,这样它就不会做任何事情。@BenRobinson编辑迁移是可行的,但很容易出错。如果有人向公司添加了
说明
属性怎么办?我应该再次编辑生成的迁移以删除
AddColumn(“Description”)
部分。除了从Accounting.dll迁移中手动删除重复的
migrationBuilder.CreateTable()
之外,您是否找到了此问题的解决方案?@randydano没有找到合适的解决方案。但是我发现EF Core中的迁移机制对于这个问题更加灵活。你可以编辑迁移,这样它就不会做任何事情了。@BenRobinson编辑迁移是可行的,但它很容易出错。如果有人向公司添加了
说明
属性怎么办?我应该再次编辑生成的迁移以删除
AddColumn(“Description”)
部分。除了从Accounting.dll迁移中手动删除重复的
migrationBuilder.CreateTable()
之外,您是否找到了此问题的解决方案?@randydano没有找到合适的解决方案。但是我发现EF Core中的迁移机制对于这个问题更加灵活。
// In Infrastructure.dll
public class Company
{
    public string Name{ get; set; }

}

public InfrastructureDbContext : DbContext
{
    // ...

    public DbSet<Company> Companies { get; set; }
}