按照此问题中的示例:How to create a many-to-many mapping in Entity Framework?我希望有一个表映射,我可以在其中添加或删除多对多关系,而无需通过Media
或{{1实体。
基本上,我想:
Contract
是否可以使用FluentAPI配置此方案?
答案 0 :(得分:0)
afaik不在ContractMedia实体,但您可以:
public class Media // One entity table
{
public int Id { get; set; }
public string Name { get; set; }
public bool Enabled { get; set; }
public virtual ICollection<ContractMedia> Contracts { get; set; }
}
public class Contract // Second entity table
{
public int Id { get; set; }
public string Code { get; set }
public virtual ICollection<ContractMedia> Medias { get; set; }
}
public class ContractMedia // Association table implemented as entity
{
public Media Media { get; set; }
public int MediaId { get; set; }
public Contract Contract { get; set; }
public int ContractId { get; set; }
}
或
public class Media // One entity table
{
public int Id { get; set; }
public string Name { get; set; }
public bool Enabled { get; set; }
public virtual ICollection<Contract> Contracts { get; set; }
}
public class Contract // Second entity table
{
public int Id { get; set; }
public string Code { get; set }
public virtual ICollection<Media> Medias { get; set; }
}
将导致在数据库中创建非映射关联表。