The specified LINQ expression contains references to queries that are associated with different contexts

青春壹個敷衍的年華 提交于 2019-12-13 13:24:39

问题


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

The specified LINQ expression contains references to queries that are associated with different contexts

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;
            }

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


回答1:


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



来源:https://stackoverflow.com/questions/4503202/the-specified-linq-expression-contains-references-to-queries-that-are-associated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!