Linq 像表一样左连接
我有两个结构相同的数据表,我需要找到第一个数据表中出现的所有记录,但第二个数据表中没有出现的记录。更复杂的是匹配需要在 3 列而不是一列上进行。
背景 - 我正在编写一个复制过程,其中数据行到达 XML 事务,并且需要将它们与“主机”数据库进行匹配,以查明是否有任何需要添加的项目。基本算法如下:
- 加载包含多个数据表的事务数据集
- 创建一个新的数据表并使用本地数据库中的“主机”条目进行填充
- 在它们之间运行匹配以找出哪些是“新”记录
- 迭代所述“新 ”记录' 在数据库中记录并创建对象。
我在 LINQ 中见过很多 LEFT JOIN 的例子,但我似乎找不到任何专门满足我需求的东西。如果将表连接到一列上,那就很容易了,但不幸的是,情况并非如此......
任何帮助将不胜感激。
谢谢,
蒂姆
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:
- Load in transaction dataset containing several datatables
- Create a new datatable and populate with the 'host' entries from the local database
- Run a match between them to find out which are the 'new' records
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 Microsoft 的101 LINQ 示例。有一个 LEFT OUTER JOIN 示例应该可以帮助您。
See Microsoft's 101 LINQ Samples. There is a LEFT OUTER JOIN example that should help you out.