I have two tables from two different Data Contexts. Although both tables are from the same database, two separate datacontexts exist.
Error message:
The query contains references to items defined on a different data context.
How can I get around this? Any help is appreciated. Thanks.
If your code does something along the lines of:
from a in dc1.TableA
join b in dc2.TableB on a.id equals b.id
select new { a, b }
...just change it to:
from a in dc1.TableA
join b in dc1.GetTable<TableB>() on a.id equals b.id
select new { a, b }
The L2S datacontext uses the attributes on the class, so if you use GetTable on another datacontext than the one the table is attached to it will just pick up the table, column, etc attributes from the class def and use it as if it was part of the DC you're using in the query...
Another solution is change the result to List().
var query = (from a in dc1.TableA
join b in dc2.TableB on a.id equals b.id
select new { a, b }).ToList()
You don't. The data contexts may have inconsistent views of the database.
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