EF 6.1

时间:2016-06-13 15:13:52

标签: c# entity-framework entity-framework-6

是否可以为一对多关系编写自定义逻辑?假设我有以下类:

public class ProductIncompatibility
{
    [Key]
    public int ProductIncompatibilityId { get; set; }
    public int ProductIdA { get; set; }
    public int ProductIdB { get; set; }

    [ForeignKey("ProductIdA")]
    public virtual Product ProductA { get; set; }

    [ForeignKey("ProductIdB")]
    public virtual Product ProductB { get; set; }
}

public class Product
{
    [Key]
    public int ProductId { get; set; }

    public virtual ICollection<ProductIncompatibility> IncompatibleProducts { get; set; }
}

当我执行以下Linq查询时:

Products.Select(it => new { it.ProductId, it.IncompatibleProducts })

Products.Include("IncompatibleProducts")

我希望ProductIdA = ProductId ||的所有ProductIncompatibility记录ProductIdB = ProductId。

是否可以指定此逻辑,例如使用modelBuilder?

0 个答案:

没有答案