排除Lambda表达式中的行

时间:2012-09-03 16:29:26

标签: lambda linq-to-entities

我有这个Linq-to-Entities表达式

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)

基本上,stringArray包含一些设施,其中一些设施与AmenitySummary中的Amenity相同。如果它们相等,我不想将其添加到结果中。

1 个答案:

答案 0 :(得分: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();