我有两个列表rtrn
和Zipcodes
rtnr项目有Utility
字段。我需要返回rtrn
的子集rtrn.Utility
field1
或filed2
或field3
zipocode
项
答案 0 :(得分:0)
从此zipcodes文件中获取独特的实用程序1-3
DbSet<Utility> utilities;
DbSet<Zipcodes> zipcodes;
var uniqeUtilitiesInZipcodes = zipcodes.Select(x => x.Field1).ToList();
uniqeUtilitiesInZipcodes.AddRange(zipcodes.Select(x => x.Field2).ToList());
uniqeUtilitiesInZipcodes.AddRange(zipcodes.Select(x => x.Field3).ToList());
uniqeUtilitiesInZipcodes = uniqeUtilitiesInZipcodes.Distinct().ToList();
将独特的实用程序与zipcodes相交
uniqeUtilitiesInZipcodes = uniqeUtilitiesInZipcodes.Distinct().ToList();
var zipcodesWhereUtilityExistsInAnyUtiltyField = utilities.Intersect(uniqeUtilitiesInZipcodes).ToList();