问题
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