views:

1847

answers:

5

I have two tables from two different Data Contexts. Although both tables are from the same database, two separate datacontexts exist.

Error msg: "The query contains references to items defined on a different data context."

How can I get around this? Any help is appreciated. Thanks.

A: 

Why don't you just include the necessary tables in each context?

Per Erik Stendahl
I get a “This member is defined more than once” error.
jinsungy
Then you're probably doing something else wrong.
Per Erik Stendahl
A: 

You don't. The data contexts may have inconsistent views of the database.

Greg D
A: 

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...

KristoferA - Huagati.com
A: 

Oh Stackoverflow how you provide!!

Simulating Cross Context Joins--LINQ/C#

Mathlec
A: 

Work great... Thank!!!

Dukemetal