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

4

1 に答える 1

9

これはあなたが求めているものですか?

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

これにより、が にないMyTable場所からすべてが選択されます。IdUserIds

于 2013-06-22T21:31:08.953 に答える