什么时候编译查询,返回一个IQueryable执行? [英] When does a compiled query that returns an IQueryable execute?

查看:87
本文介绍了什么时候编译查询,返回一个IQueryable执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我在这里需要一个全面的检查......

Okay I need a sanity check here...

我编译执行时,返回一个IQueryable查询。

I've compiled a query that returns an IQueryable when executed.

那一行(S)应查询实际对数据库下面的示例执行?

101 IQueryable<T> results = MyCompiledQuery(MyDataContext);
102 List<T> final = (from t in result
103                  where t.ID > 5
104                  select t).ToList<T>();

下面是我如何定义编译的查询

Here is how I define the compiled query

 public static Func<MyDataContext, IQueryable<Widget>> MyCompiledQuery=
        CompiledQuery.Compile<MyDataContext, IQueryable<Widget>>(
                      (MyDataContext db) =>
                      from w in db.Widgets
                      where ((w.Type == WidgetType.Atype ||  //Widget.Atype is a Linq to Sql object, that I've defined statically
                              w.Type == WidgetType.Btype ||  //See above comment
                              w.Type == WidgetType.Ctype ) && //See above comment
                              w.Location == WidgetLocation.Domestic)  //Samething applies here
                        select euc);

有更多的讨论请参见: <一href="http://stackoverflow.com/questions/6592386/linq-to-sql-compiled-queries-and-when-they-execute/6597160#6597160">LINQ到SQL的编译的查询,当他们执行

FOR ADDITIONAL DISCUSSION PLEASE REFER TO: LINQ to SQL compiled queries and when they execute

推荐答案

关于做好了ToList转换时行104。

"On the line 104, when doing ToList conversion."

嗯,这个答案是不正确。我们调用代表存储在MyCompiledQuery变量上线101返回已编译的查询的结果,而不是查询本身

Well, this answer is incorrect. We invoke delegate stored in MyCompiledQuery variable on line 101 that returns the result of the compiled query, not the query itself.

这篇关于什么时候编译查询,返回一个IQueryable执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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