views:

30

answers:

4

In normal sql I could do joins on tables in different databases as long as they were on the same server (or linked servers). In linq I can't figure out how to do that. Is this possible? For example, if I have a database called db1 and another called db2. db1 has a table called people and db2 has a table called address I could do something like...

select a.addressline1, p.firstname
from db1.dbo.people p
inner join db2.dbo.address a on p.peopleid = a.peopleid

Is this possible with linq? Thanks.

A: 

Personally when i need joins in LINQ-to-SQL i just make them in SQL. With LINQ they're rather difficult to write but it should be possible with the .JOIN selector in LINQ.

Another way to writing LINQ-queries is explained here

Rob
A: 

Multiple databases under a single context is not directly supported. Create views in the first database that point at tables in the second, and map entities to those views.

This article also shows this, and an alternative option by manually editing the datasource property:

http://damieng.com/blog/2010/01/11/linq-to-sql-tips-and-tricks-3

SteadyEddi
Yes, this seemed to be the most straightforward way to accomplish it. Thanks.
geoff swartz
A: 

try using db1.ExecuteQuery(@"your query")

HTH

Raja