I have 2 var from same DBs, after union:
var projectedP1 = P1.Select(x => new Project_test {
ID_inString = x.ID.ToString(),
col1 = x.col1,
col2 = x.col2,
col3 = x.col3 });
var union = projectedP1.Union(P2);
when P1 alone or P2 alone, everything is fine But when 2 is union, i get this in run-time:
The query contains references to items defined on a different data context.
I tried this similar post, but dun understand. ANyone has any idea?
The specified LINQ expression contains references to queries that are associated with different contexts
You can never join objects from two different contexts; because the union is compiled into a database query, it wouldn't know how to execute it since multiple DB's are not supported. The best you can do is to call ToList() on each query separately, which will execute the database queries, and do a LINQ-to-Objects union. This is entirely an iterative process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With