Entity framework 实体框架无连接实体的多对多导航
具有下表结构 如何在我的小部件类中创建由CompanyId过滤的链轮导航属性,而不必在公司实体中添加和使用链轮导航属性Entity framework 实体框架无连接实体的多对多导航,entity-framework,Entity Framework,具有下表结构 如何在我的小部件类中创建由CompanyId过滤的链轮导航属性,而不必在公司实体中添加和使用链轮导航属性 class Widget { public int CompanyId {get; set;} public virtual ICollection<Sprocket> Sprockets {get; set;} } 类小部件{ public int CompanyId{get;set;} 公共虚拟ICollection链轮{get;set;} }
class Widget {
public int CompanyId {get; set;}
public virtual ICollection<Sprocket> Sprockets {get; set;}
}
类小部件{
public int CompanyId{get;set;}
公共虚拟ICollection链轮{get;set;}
}
我想答案是,没有,至少还没有。EF Core 5中添加了“跳过集合”,但目前它们仅支持多对多关系,其中链接实体位于两个关系的多个方面。看
当然,您可以添加NotMapped属性,但不能在LINQ to实体中使用它
public class Widget
{
public int WidgetId { get; set; }
public string Name { get; set; }
public virtual Company Company { get; set; }
[NotMapped]
public ICollection<Sprocket> Sprockets
{
get
{
return this.Company.Sprockets;
}
}
}
公共类小部件
{
public int WidgetId{get;set;}
公共字符串名称{get;set;}
公共虚拟公司公司{get;set;}
[未映射]
公共i收集链轮
{
得到
{
退回本公司链轮;
}
}
}