How To Join Tables from Two Different Contexts with LINQ2SQL?

Posted by RSolberg on Stack Overflow See other posts from Stack Overflow or by RSolberg
Published on 2010-03-24T17:01:54Z Indexed on 2010/03/24 17:03 UTC
Read the original article Hit count: 189

Filed under:
|
|

I have 2 data contexts in my application (different databases) and need to be able to query a table in context A with a right join on a table in context B. How do I go about doing this in LINQ2SQL?

Why?: We are using a SaaS product for tracking our time, projects, etc. and would like to send new service requests to this product to prevent our team from duplicating data entry.

Context A: This db stores service request information. It is a third party DB and we are not able to make changes to the structure of this DB as it could have unintended non-supportable consequences downstream.

Context B: This data stores the "log" data of service requests that have been processed. My team and I have full control over this DB's structure, etc. Unprocessed service requests should find their way into this DB and another process will identify it as not being processed and send the record to the SaaS product.

This is the query that I am looking to modify. I was able to do a !list.Contains(c.swHDCaseId) initially, but this cannot handle more than 2100 items. Is there a way to add a join to the other context?

var query = (from c in contextA.Cases
             where monitoredInboxList.Contains(c.INBOXES.inboxName)
             select new
             {
                 //setup fields here...
             });

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-sql