C# LINQ到SQL和编译查询
我有一个编译后的查询,返回一个C# LINQ到SQL和编译查询,c#,.net,linq,linq-to-sql,C#,.net,Linq,Linq To Sql,我有一个编译后的查询,返回一个IQueryable。如果执行编译后的查询,结果是否缓存在我传递的DataContext中 using(context) { var count = MyCompiledQuery(context).Count(); //Does the call to MyCompiledQuery execute against the database again, or does it go to the context for results?
IQueryable
。如果执行编译后的查询,结果是否缓存在我传递的DataContext中
using(context)
{
var count = MyCompiledQuery(context).Count();
//Does the call to MyCompiledQuery execute against the database again, or does it go to the context for results?
var first10 = MyCompiledQuery(context).Take(10);
}
这是一个使用C#的.NET 3.5应用程序。是的,再次执行查询。您可以通过与应用程序并行运行SQL Profiler来查看它。实现此功能的唯一方法是首先获取所有记录并执行ToList()或ToArray(),然后对列表或数组运行Count()和Take(10)。但我猜你不想得到所有的结果 这里可以做的一个优化是显式地打开和关闭连接,但我已经读到连接池非常有效,您可能不会注意到太多差异
请不要缩短标签,尤其是我亲爱的LINQ to SQL%)我没有缩短任何标签,我选择的都是自动完成给我的。