I have this query:
var list = (from t1 in context1.SomeTable
join t2 in context2.SomeTable on t1.ID equals t2.ID
where //some where clause
select new { t1.SomeField, t2.SomeField }).ToList());
I will get this error when this query tries to execute:
The specified LINQ expression contains references to queries that are associated with different contexts.
- Why is this not allowed with
LINQ to Entities
? - Is it still possible with
L开发者_高级运维INQ to Entities
in another way? - What would be a work around for this?
I'd imagine it's because the statement you're building up is converted to SQL behind the scenes and run on the database. Because different context could come from different databases or even different servers, there's no guarantee that the data in context2 is available to context1 when the server is being queried.
You could return the data from each context and convert to IEnumerable and then perform standard linq queries then but you've got a clear overhead of data transfer and in-memory processing that would have otherwise been performed by the database engine.
精彩评论