5

I am trying to retrieve this in linq but can't seem to figure it out. I want to filter a query based on if a value in the query exist in a list but remove those items from the query.

Let say I have a list of ids

List<int> UserIds = new List<int>(); //contains 1 2 3

var query = MyTable.Where(a=>a.Id.Notexist(UserIds))

basically I would want to remove all items from the UserId list from the query) so query should not return items with Id = 1,2, or 3

Jake
  • 1,332
  • 5
  • 23
  • 35

1 Answers1

9

Is this what you're after?

MyTable.Where(a => !UserIds.Contains(a.Id))

This will select everything from MyTable where the Id is not in UserIds.

Ant P
  • 24,820
  • 5
  • 68
  • 105
  • 1
    @Jake If this answer resolved your issue, please mark it as accepted to indicate this to future viewers. – Ant P Jun 24 '13 at 10:05