var List = from book in books where book.price > 50 select book;List = List.Take(50);
我会期望以上产生如下:
SELECT top 50 ID,Title,price,authorFROM BooksWHERE 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]解决方法 你仍然可以像这样清洁:
var c = (from co in db.countrIEs where co.regionID == 5 select co).Take(50);
这将导致:
table(country).Where(co => (co.regionID = Convert(5))).Take(50)
相当于:
SELECT top (50) [t0].[countryID],[t0].[regionID],[t0].[countryname],[t0].[code]FROM [dbo].[countrIEs] AS [t0]WHERE [t0].[regionID] = 5
编辑:评论,它不一定是因为单独的Take(),你仍然可以这样使用它:
var c = (from co in db.countrIEs where co.regionID == 5 select co); var l = c.Take(50).ToList();
结果与以前相同.
SELECT top (50) [t0].[countryID],[t0].[code]FROM [dbo].[countrIEs] AS [t0]WHERE [t0].[regionID] = @p0
你写的Iqueryable = Iqueryable.Take(50)的事实在这里很棘手.
总结以上是内存溢出为你收集整理的c# – 为什么以下linq到sql查询生成一个子查询?全部内容,希望文章能够帮你解决c# – 为什么以下linq到sql查询生成一个子查询?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)