15

Is it possible to perform joins across different databases using LINQ? If yes then how?

bluish
  • 26,356
  • 27
  • 122
  • 180
santosh singh
  • 27,666
  • 26
  • 83
  • 129

2 Answers2

23

If the databases are on the same server, you can create views (and 3 part naming) so that all the tables are queryable from one database.

If the databases are on different servers, you can use linked servers and views (and 4 part naming) so that all the tables are queryable from one database.

Amy B
  • 108,202
  • 21
  • 135
  • 185
  • 2
    +1 - this is my preferred answer and a tecnnique I've used a few times now in emergencies :) – Andras Zoltan Nov 25 '10 at 22:06
  • 1
    This should really be flagged as the proper answer. You immediately are managing multiple context/model connection strings and more complex linq queries for no reason with the current accepted answer. – Brian Ogden Jun 07 '13 at 01:20
  • It's also possible to use 3 part naming in the table attribute. – Amy B Apr 03 '14 at 02:00
0

calling .ToList() is querying all the records in db, so it will eat a lot of memory if there are a lot of records in tables.

Or try this one The specified LINQ expression contains references to queries that are associated with different contexts.

Community
  • 1
  • 1
jmvtrinidad
  • 3,347
  • 3
  • 22
  • 42
  • 1
    With a bit more rep, [you will be able to flag duplicate questions like this](http://stackoverflow.com/privileges/comment), as well as mention side-notes like performance considerations in comments. Until then, posting links or commentary as answers is not really ideal, and they will generally be deleted. – Nathan Tuggy May 15 '15 at 02:00
  • 2
    I should say it is kind of duplicate question, right? Thanks! – jmvtrinidad May 15 '15 at 03:40