1

I have this Linq-to-Entities expression

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();

And I also have a string array which contains amenities that I want to exclude from this list. Is there some way of doing something like this at the end

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

So basically, stringArray contains amenities some of which will equal Amenity in AmenitySummary. If they equal I don't want to add that to the result.

piokuc
  • 25,594
  • 11
  • 72
  • 102
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • http://stackoverflow.com/questions/183791/how-would-you-do-a-not-in-query-with-linq may be related. – JayC Sep 03 '12 at 16:40

1 Answers1

0

Try something like the following:

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();
luksan
  • 7,661
  • 3
  • 36
  • 38