gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:46:42 25 4
gpt4 key购买 nike

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

最佳答案

您可以尝试使用 GetTable命令。我认为这会首先加载所有 contextB.TableB 的数据,但不能 100% 确定这一点。我没有设置环境来玩或测试它所以让我知道它是否有效 =)

from a in contextA.TableA
join b in contextB.GetTable<TableB>() on a.id equals b.id
select new { a, b }

关于c# - 如何使用 LINQ2SQL 连接来自两个不同上下文的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2509723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com