.net - LinqToSQL Select 和 SelectMany 与 Join

标签 .net sql linq linq-to-sql .net-3.5

很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center .




9年前关闭。




Select 和 SelectMany 是否比 Joins 更可取?

我想知道的原因是因为我使用 LinqPad 并且在一个部分中有评论说:

// Note: before delving into this section, make sure you've read the preceding two
// sections: Select and SelectMany. The Join operators are actually unnecessary
// in LINQ to SQL, and the equivalent of SQL inner and outer joins is most easily
// achieved in LINQ to SQL using Select/SelectMany and subqueries!

然而,在其他部分,它清楚地表明连接更快(至少对于 LinqPad 中给出的示例),并且对我来说它们更容易在我的脑海中可视化。

也许我误解了,因为我只查看代码示例而不是本书,但我看到其他人也推荐 Select 和 SelectMany 而不是 Joins。

最佳答案

任性的博客有this to say关于此事。 Join 使用一组显式参数来连接特定键,并允许左外连接和右外连接。 SelectMany 执行 monadic bind这通常会导致内部联接或交叉联接。由于 LINQ 本质上是 .NET 中函数式编程的实现,因此 SelectMany 是更自然的表达;然而,Join 的显式设置可能会导致更快的操作。

至于首选,我认为对您来说最清楚的内容是最好的。 C# version of 101 LINQ Samples不包括 Join,但 VB list展示了不同场景下使用的Join和SelectMany。

关于.net - LinqToSQL Select 和 SelectMany 与 Join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/481023/

相关文章:

c# - 为什么我在使用 SetPixel : SetPixel is not supported for images with indexed pixel formats? 时出现异常

sql - 告诉我有关sql查询两个表的信息

c# - 如何加入 2 个字符串列表,其中 Key 与 Linq 匹配和 SUM

c# - 如何以类型安全的方式编写以列名作为参数的 LINQ 查询

c# - Marshal.AllocHGlobal(0) - 为什么这不返回 IntPtr.Zero

c# - 什么是 GC 漏洞?

从上周开始的不同时间段的 MySQL 用户事件

c# - 展平 LINQ 集合

.net - 如果使 IE8 模拟 IE7 的 head 标签不起作用怎么办?

SQL Server 'In' 语句项性能顺序