我有一对多的字典,我需要查找数据中发送给用户的任何差异。下面是我的查询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