我正在尝试根据与公司匹配的用户名返回结果。涉及5张表。我可以做一个子选择(显然不是)或者最好的方法是什么。
db.Displays
.Include(d => d.Location)
.Include(d => d.Location.Region)
.Include(d => d.Location.Region.Company.Users.Where(p=> p.LoginName == userName);
最佳答案
您不需要应用前两个Includes
,第三个您应该能够包含您需要的级别:
var displays= db.Displays.Include(d=>d.Location.Region.Company.Users).Where(d=>d.Location.Region.Company.Users.Any(p=>p.LoginName== userName));
在Include
之后,您需要调用Where
方法来按您要应用的条件过滤显示。
关于c# - Entity Framework 子选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29611441/