LINQ对象 [英] Linq to objects

查看:81
本文介绍了LINQ对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个来自不同服务器的数据库.我无法链接数据库.数据从数据库中检索为:

I have 2 databases from different servers. I cannot link the databases. The data is retrieved from the databases as :

DB1

-已启用Client_ID参与ID的描述

  • 600 10真实公司1
  • 600 20虚假公司2
  • 700 10 True Company3

DB2

  • 已启用Client_ID参与ID 说明

  • Client_ID Engagement_ID Enabled Description

600 5 True Company1

600 5 True Company1

600 10虚假公司2

600 10 False Company2

500 30 True Company3

500 30 True Company3

此任务的T SQL是:

The T SQL for this task is:

select * from DB1
left join DB2 on DB1.client_ID = DB2.client_ID
and DB1.Engagement_ID = DB2.Engagement_ID
where DB2.CLient_ID is null
and DB2.Engagement_ID is null and DB1.client_id in (select client_id from DB2)

我需要执行此VB.NET LINQ

I need to do this VB.NET LINQ

推荐答案

    Dim list1 = From obj1 As DBObject In DB1 _
                   Group Join obj2 As DBObject In DB2 _
                   On obj1.ClientId Equals obj2.ClientId _
                   And obj1.EngagementId Equals obj2.EngagementId _
                   Into g = Group _
                   From r In g.DefaultIfEmpty() _
                   Where g.ElementAtOrDefault(0) Is Nothing _
                   Select New With {.Cl_ID = obj1.ClientId, .EngID = bj1.EngagementId}  


    Dim list2 = (From obj3 In list1 _
                  From obj4 In DB2 _
                  Where obj3.Cl_ID = obj4.ClientId _
                  Select obj3).Distinct.DefaultIfEmpty

我修改了sunpech的代码,并且List2包含了预期的结果,即DB1的第二行-600、20,False,"Company2"

I modified sunpech's code and List2 contains the expected result i.e. the second row of DB1 - 600, 20, False, "Company2"

这篇关于LINQ对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆