2012-09-03 54 views
1

我有這樣的LINQ到實體表達排除行在Lambda表達式

return 
       (from aa in DataContext.AccommodationAmenities 
       join a in DataContext.Amenities 
        on aa.AmenityId equals a.Id 
       where a.LowerCaseAmenity.Contains(lowerCaseSearchTerm) 
       select new AmenitySummary 
          { 
           AmenityId = a.Id, 
           Amenity = a.Amenity1, 
           LowerCaseAmenity = selected//a.LowerCaseAmenity 
          }).Distinct(); 

而且我也有一個字符串數組它包含我想從這個列表中排除的設施。有沒有在年底做這樣的事情的一些方法

.Exclude(a => a.Amentiy == stringArray) 

所以基本上,字符串數組包含設施其中一些將等於美化在AmenitySummary。如果他們平等,我不想將其添加到結果中。

+0

http://stackoverflow.com/questions/183791/how-would-you-do-a-not-in-query-with-linq可能與。 – JayC

回答

0

嘗試類似如下:

return 
       (from aa in DataContext.AccommodationAmenities 
       join a in DataContext.Amenities 
        on aa.AmenityId equals a.Id 
       where a.LowerCaseAmenity.Contains(lowerCaseSearchTerm) 
         && !stringArray.Contains(a.Amenity1) 
       select new AmenitySummary 
          { 
           AmenityId = a.Id, 
           Amenity = a.Amenity1, 
           LowerCaseAmenity = selected//a.LowerCaseAmenity 
          }).Distinct();