改为使用您的SupplierProduct
班级作为关系:
class SupplierProduct {
public int SupplierId { get; set; }
public int ProductId { get; set; }
// additional properties specific to a S+P combo:
public bool IsProductAssembled { get; set; }
}
class Product {
// ... lot of properties
// Link all the suppliers of this products
public IList<SupplierProduct> Suppliers { get; set; }
}
class Supplier {
// ... lot of properties
// Link all the product this supplier supplies
public IList<SupplierProduct> Products { get; set; }
}
然后,配置Product
有很多Suppliers
和Supplier
有很多Products
. Product
和之间没有直接关系Supplier
。
配置模型绑定器:
modelBuilder.Entity<Product>()
.HasMany<SupplierProduct>(p => p.Suppliers)
.WithRequired();
modelBuilder.Entity<Supplier>()
.HasMany<SupplierProduct>(s => s.Products)
.WithRequired();