是否可以为一对多关系编写自定义逻辑?假设我有以下类:
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?