c# - Entity Framework 6 - 选择 child 平等的 parent

标签 c# linq entity-framework-6

我只需要父对象。在 SQL 中,这很简单:

select distinct * from parent 
join child on child.ParentID = Parent.ID 
where child.playssoccer = true;

在 Entity Framework 6 中,这对我来说就像拆分原子。

我需要新的 p => parent where parents.children.playssoccer = true 。

如何从类似的 EF6 DBContext 中获取足球 parent ?

最佳答案

from p in context.Parents
where p.Children.Any(c => c.PlaySoccer == true)
select p

这是假设您希望 parent 至少有一个踢足球的 child 。

关于c# - Entity Framework 6 - 选择 child 平等的 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23571365/

相关文章:

c# - EF6 - 代码优先 - 如何正确处理从 m :n relationship 中删除父条目

c# - 连续两次对同一方法的最小起订量期望

c# - collections.Contains(T) 方法

c# - c# 中的单元测试项目与带有 xunit 的类库之间的区别

c# - 将 Generic.List<int?> 转换为 Generic.List<int>

entity-framework - LinqWhere(p => p.Parent == null) 在自引用表中如何工作?

c# - 从 Entity Framework 5 升级到 6

entity-framework-6 - 使用 Azure Active Directory 从 Azure 网站连接到 Azure SQL?

c# - Microsoft Solver Foundation 在添加约束时抛出 ArgumentNullException

c# - Linq 是否消除了对 Hibernate 的需求?