【发布时间】:2022-08-09 21:49:16
【问题描述】:
如何根据多列匹配左连接 2 个数据表? 为了比较右表中哪些数据行不匹配
增量上传的一部分需要只从源数据表中引入新行
如何根据多列匹配左连接 2 个数据表? 为了比较右表中哪些数据行不匹配
增量上传的一部分需要只从源数据表中引入新行
找到了一种使用 LINQ 在 c# 中使用 join 比较两个数据表的方法(左)
IEnumerable<DataRow> result = (from srcDt in dtSource.AsEnumerable()
join dstDt in dtDestination.AsEnumerable()
on new { EmployeeID = srcDt["EmployeeID "], Environment = srcDt["Environment"] } equals new { EmployeeID = dstDt["EmployeeID "], Environment = dstDt["Environment"] }
into g
from row in g.DefaultIfEmpty()
where row == null
select srcDt);
// verify if the result has any rows in the dataset
if (result.Any())
{
DataTable dtInserts = result.CopyToDataTable();
// other code which uses the new datarows to perform inserts
}
【讨论】: