linq - 如何在针对 Entity Framework 的 LINQ 查询中执行 "join"

标签 linq entity-framework linq-to-entities linq-to-objects

我有下面的表结构,它已导入到 Entity Framework 中。我需要编写一个 LINQ 查询,我在其中选择表 1 的实体,其中表 2 中的一个字段等于 true,表 3 中的一个字段等于特定的 GUID。

有人可以帮忙吗?

谢谢。

alt text http://digitalsamurai.us/images/drawing2.jpg

最佳答案

尝试:

from t3 in dataContext.Table3
  where t3.Guidfield == someGuid
  from t2 in t3.Table2
  where t2.Field // boolean field is true
  select t2.Table1;

编辑: 根据要求,等效的 lambda 表达式语法:

dataContext.Table3.Where(t3 => t3.Guidfield == someGuid)
              .SelectMany(t3 => t3.Table2)
              .Where(t2 => t2.Field)
              .Select(t2.Table1);

关于linq - 如何在针对 Entity Framework 的 LINQ 查询中执行 "join",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2225099/

相关文章:

c# - Linq 比较 C# 中的两个集合

c# - 使用 LINQ 比较两个数组

asp.net-mvc - virtual 关键字、Include 扩展方法、延迟加载、预先加载——加载相关对象实际上是如何工作的

c# - 如何在 LINQ to entities 中使用 Date 函数?

c# - 如何编写 SQL 交叉联接的 Linq 表达式?

asp.net - CRM 插件 - Linq 结果中缺少属性

c# - Linq.Max InvalidOperationException(结果中没有元素)

c# - Entity Framework 中的导航属性问题

c# - 我怎样才能得到linq中的计数?

c# - Entity Framework 遍历并返回自引用表中的子记录