0
我正在兩列上連接表,並且需要查找第三列不匹配的記錄。Linq加入具有where not equals條件的多堆列,並且需要從兩個表中返回列
我有LINQ查詢將從表1返回正確的記錄,但我無法從第二個表中選擇日期列。
我嘗試了分組結果,但遇到了「不等於」條件的問題。
所以,我有這些記錄:
表1:4SONS,112,2016年9月3日
表2:4SONS,112,2016年9月26日
我需要回報是 - 4SONS,112,2016年9月3日,2016年9月26日
但我的查詢只返回 - 4SONS,112,09/03/2016沒有辦法從表2中獲取該日期。這些是每個表中唯一的3列。
var query = from s in schedTable.AsEnumerable()
where s.Field<DateTime?>("AuditDate").HasValue
join c in completeTable.AsEnumerable()
on new { account = s.Field<string>("Account").ToString(), store = s.Field<string>("Store").ToString()}
equals new { account = c.Field<string>("Account").ToString(), store = c.Field<string>("Store").ToString() }
where s.Field<DateTime>("AuditDate").Date != c.Field<DateTime>("AuditDate").Date
select s;
var typeD = query.ToList();
結果顯然是不能的數據記錄列表。創建一個類並使用'select new YourClass {...}'。或者是匿名類型。 –