[英]Entity Framework 6 - Select Parents Where Children Equal
我只需要Parent對象。 在SQL中,這很簡單:
select distinct * from parent
join child on child.ParentID = Parent.ID
where child.playssoccer = true;
在實體框架6中,這似乎將原子分裂給我。
我需要新的p => parent,其中parents.children.playssoccer = true。
如何從類似的EF6 DBContext中獲取足球父母?
from p in context.Parents
where p.Children.Any(c => c.PlaySoccer == true)
select p
這假設您希望父母至少有一個孩子踢足球。
如果你有導航屬性,你可以做類似的事情
Parents.Where(p => p.child.playsoccer)
Parents
.Where(p=> p.child.playsoccer)
.GroupBy(p=> p.Parent.ID)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.