指定的LINQ表达式包含与不同上下文关联的查询的引用 [英] The specified LINQ expression contains references to queries that are associated with different contexts

查看:187
本文介绍了指定的LINQ表达式包含与不同上下文关联的查询的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试加入查询中的多个表时,我收到错误:

I'm getting an error when trying to join against multiple tables in a query:

指定的LINQ表达式包含对与不同的上下文

令人困惑的是因为它使我看起来像在查询中使用不同的上下文,但我不是:

It's confusing because it makes it seem like I'm using different contexts within the query but I'm not:

public static IQueryable<Company> GetAll(bool supportsMMAT)
            {
                return from c in Context.Companies
                            join v in Context.Vehicles on c.CompanyIdNumber equals v.CompanyIdNumber
                            join mt in Context.ModemTypes on v.ModemTypeId equals mt.Id
                            where !c.CompanyShutOff
                                && (!supportsMMAT || mt.Model == "MMAT")
                            select c;
            }

任何想法?我正在使用EF4 CTP5代码第一种方法,如果这有任何区别...

Any ideas? I'm using the EF4 CTP5 code first approach, if that makes any difference...

推荐答案

如果您的上下文财产每次都会返回一个新的实例。

This can happen if your Context property returns a new instance every time.

这篇关于指定的LINQ表达式包含与不同上下文关联的查询的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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