我做了以下查询:
var list = from book in books
where book.price > 50
select book;
list = list.Take(50);
我希望上面的内容会生成如下内容:
SELECT top 50 id, title, price, author
FROM Books
WHERE price > 50
但它会生成:
SELECT
[Limit1].[C1] as [C1]
[Limit1].[id] as [Id],
[Limit1].[title] as [title],
[Limit1].[price] as [price],
[Limit1].[author]
FROM (SELECT TOP (50)
[Extent1].[id] as as [Id],
[Extent1].[title] as [title],
[Extent1].[price] as [price],
[Extent1].[author] as [author]
FROM Books as [Extent1]
WHERE [Extent1].[price] > 50
) AS [Limit1]
为什么上面的 linq 查询会生成子查询,C1 来自哪里?
免责声明:我以前从未使用过 LINQ...
我的猜测是分页支持?我猜你有某种Take(50, 50)
方法获取 50 条记录,从记录 50 开始。看看查询生成的 SQL,您可能会发现它使用类似的子查询结构,以允许它在大约相同的时间内返回查询中的任何 50 行它返回前 50 行。
在任何情况下,嵌套子查询都不会增加任何性能开销,因为它在执行计划编译期间会自动优化掉。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)