什么是正确的方式使用LINQ to枚举? [英] What is the right way to enumerate using LINQ?

查看:688
本文介绍了什么是正确的方式使用LINQ to枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code:

 var result = db.rows.Take(30).ToList().Select(a => AMethod(a));

db.rows.Take(30)是LINQ到SQL

db.rows.Take(30) is Linq-To-SQL

我用了ToList()来枚举结果,因此查询的其余部分未转换为SQL

I am using ToList() to enumerate the results, so the rest of the query isn't translated to SQL

这是这样做的最快方法是什么?的ToArray()?

Which is the fastest way of doing that? ToArray()?

推荐答案

使用<一个href="http://msdn.microsoft.com/en-us/library/bb335435.aspx"><$c$c>Enumerable.AsEnumerable:

var result = db.rows
               .Take(30)
               .AsEnumerable()
               .Select(a => AMethod(a));

这篇关于什么是正确的方式使用LINQ to枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆