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
C# | Remove all elements of a List that match the conditions defined by the predicate. List<T>. RemoveAll(Predicate<T>) Method is used to remove all the elements that match the conditions defined by the specified predicate.
You can delete rows in a database by removing the corresponding LINQ to SQL objects from their table-related collection. LINQ to SQL translates your changes to the appropriate SQL DELETE commands. LINQ to SQL does not support or recognize cascade-delete operations.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With