在Select Distinct LINQ Expression中修改查询。
问题描述:
嗨团队,
很高兴见到你们。我在LINQ Expression中编写了查询。
我想在Select distinct LINQ表达式中修改该查询,是否可能。请指导ME。查询如下:
Hi Team,
Nice to see you all. I have written the query in LINQ Expression.
I want to modify that query in Select distinct LINQ expression,is it possible .please Guide ME.The Query is as follows:
string[] matchID = zteBbhRecords.Cast<IZteBbh>().Select(zteBbh => (zteBbh.CombinedMaster as ICombinedMaster).CellId.ToString()).GroupBy(item => item).Where(items => items.Count() > 1).Select(item => item.Key).ToArray();
答
因此,使用Distinct()。ToArray(),我们可以轻松获取不同的值并将它们转换为数组。
So, using Distinct().ToArray(), we can easily get the distinct values and convert them to array.
string[] matchID = zteBbhRecords.Cast<IZteBbh>()
.Select(zteBbh => (zteBbh.CombinedMaster as ICombinedMaster)
.CellId.ToString()).GroupBy(item => item)
.Where(items => items.Count() > 1)
.Select(item => item.Key).Distinct().ToArray();