c# – 如何使用LINQ2SQL连接两个不同上下文的表?

我的应用程序中有2个数据上下文(不同的数据库),需要能够在上下文中查询上下文A中的表,并在上下文中的表上使用右连接.如何在LINQ2SQL中执行此操作?Why?: We are using a SaaS product for tracking our time, projec...

我的应用程序中有2个数据上下文(不同的数据库),需要能够在上下文中查询上下文A中的表,并在上下文中的表上使用右连接.如何在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.

这是我想要修改的查询.我最初能够做一个!list.Contains(c.swHDCaseId),但这不能处理超过2100个项目.有没有办法将连接添加到其他上下文?

var query = (from c in contextA.Cases
             where monitoredInboxList.Contains(c.INBOXES.inboxName)
             //right join d in contextB.CaseLog on d.ID = c.ID....
             select new
             {
                 //setup fields here...
             });

解决方法:

在数据库解决方案之外,最好的办法是在执行后使用LINQ(对象)进行连接.

我意识到这不是你所希望的解决方案.至少在这个级别,你不必担心IN列表限制(.Contains)

编辑:
在上面的数据库解决方案之外真正指向链接服务器解决方案,其中允许来自上下文A的表/视图从上下文B存在于数据库中.

本文标题为:c# – 如何使用LINQ2SQL连接两个不同上下文的表?

基础教程推荐