我有一對多的字典,我需要查找數據中發送給用戶的任何差異。下面是我的查詢C#LINQ查找一對多差異
var FinalQuery = from final in masterquery
where final.gpa_vsl != string.Empty || final.eta1_datetime.Date.CompareTo(final.eta_date.Date) != 0 ||
final.ata_date > DateTime.MinValue || final.cfit_vsl != final.gpa_vsl
group final by final.file_no into newGroup
orderby newGroup.Key
select newGroup;
var Finaldict = FinalQuery.ToDictionary(g => g.Key, g => g.ToList());
foreach(var file in FinalDict) {
if (file.Value.Count() > 1) {
//Here I need to find out if all eta1 and all vessel match
//below is what I am trying to do with Linq
bool match = from f in file.Value
where file.Value.Count(f => f.eta1_date.CompareTo(f.eta1_date)) = file.Value.Count()
select true;
//What I am trying to do is if all eta1 dates match return a total int to compare to the total count of values.
}
}
解釋是這樣的:
Key - FileNo = 123
Value - Container = 123 , eta1 = 2/20/17, ata1 = 2/20/17, vessel = boat1
Value - Container = 456, eta1 = 2/18/17, ata1 = 2/18/17, vessel = boat2
Value - Container = 789, eta1 = 2/20/17, ata1 = 2/20/17, vessel = boat1
Value - Container = 987 , eta1 = 2/20/17, ata1 = 2/20/17, vessel = boat1
我願意接受任何和所有的建議。需要找到容器456信息與其他信息不匹配。希望我提供足夠的信息
你可以闡述什麼是你的榜樣字典中的差異? – pquest
我們的目標是讓所有eta1,ata1和船隻匹配。在上面的eta1不符合eta1的其餘部分。如果全部不匹配,那麼我需要向用戶返回一個異常 –
只需注意'orderby'後跟''.ToDictionary'破壞了順序,因爲字典在枚舉時不保證任何順序 – tinudu