Linq左连接像表 [英] Linq left-joining like tables

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

问题描述

我有2个结构相同的数据表,我需要找到所有出现在第一个而不是第二个上的记录.更为复杂的是,匹配需要在3列而不是1列上.

背景-我正在编写一个复制过程,其中数据行通过XML事务到达,并且需要将它们与主机"数据库进行匹配,以找出是否需要添加任何项目.基本算法如下:

  1. 加载包含多个数据表的交易数据集
  2. 创建一个新的数据表,并使用本地数据库中的主机"条目填充
  3. 进行匹配以找出哪些是新"记录
  4. 遍历所述新"记录并在数据库中创建对象.

我在LINQ上看到过许多LEFT JOIN的例子,但是我似乎找不到任何可以满足我需求的东西.如果将表连接到一列上会很容易,但是不幸的是事实并非如此.

任何帮助将不胜感激.

谢谢

蒂姆

解决方案

请参阅Microsoft的 101个LINQ样本.有一个左外连接示例可以为您提供帮助.

I have 2 datatables of identical structure, and I need to find all records that appear on the first, but not on the second. What makes it more complicated is that the matching needs to be on 3 columns instead of one.

Background - I'm writing a replication process where rows of data arrive in an XML transaction and they need to be matched against the 'host' database to find out if there are any items that need to be added. The basic algorithm is as follows:

  1. Load in transaction dataset containing several datatables
  2. Create a new datatable and populate with the 'host' entries from the local database
  3. Run a match between them to find out which are the 'new' records
  4. Iterate through said 'new' records and create the objects in the database.

I've seen many examples of LEFT JOIN in LINQ but I can't seem to find anything that specifically meets my needs. It would be easy if the tables were joined on one column, but unfortunately this is not the case....

Any help would be appreciated.

Thanks,

Tim

解决方案

See Microsoft's 101 LINQ Samples. There is a LEFT OUTER JOIN example that should help you out.

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

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