如何使EF存在查询?

时间:2016-01-06 17:57:44

标签: entity-framework-6

我有两个列表rtrnZipcodes

rtnr项目有Utility字段。我需要返回rtrn的子集rtrn.Utility field1filed2field3 zipocode

1 个答案:

答案 0 :(得分:0)

  1. 从此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();
    
  2. 将独特的实用程序与zipcodes相交

        uniqeUtilitiesInZipcodes = uniqeUtilitiesInZipcodes.Distinct().ToList();
    
        var zipcodesWhereUtilityExistsInAnyUtiltyField = utilities.Intersect(uniqeUtilitiesInZipcodes).ToList();