更改现有的IQueryable&所述的ObjectContext中;> [英] Changing the ObjectContext of an existing IQueryable<>

查看:160
本文介绍了更改现有的IQueryable&所述的ObjectContext中;>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有得到我想要的一些插件(计数,分页)在不同的线程执行查询的方法。

I have a method that gets a query that I want to execute with some addons (count, paging) on different threads.

该方法可以得到不同的查询返回相同的的IQueryable< someEntity>

The method can get different queries that returns the same IQueryable<someEntity>.

有没有一种方法来创建一个EF查询和设置的ObjectContext它以后呢?

Is there a way to create an EF query and set the ObjectContext to it later ?

感谢。

推荐答案

这是不可能的。 IQueryable的(和的ObjectQuery)是依赖于创建它的上下文。作为一种变通方法,您可以使用包含您的查询,返回的IQueryable并接受上下文参数自定义静态方法。同样priciple之后是pre编译查询,这是上下文无关。

It is not possible. IQueryable (and ObjectQuery) is dependent on context which created it. As a workaround you can use custom static method containing your query, returning IQueryable and accepting context as parameter. The same priciple is followed by pre-compiled queries which are context independent.

这篇关于更改现有的IQueryable&所述的ObjectContext中;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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