Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq except return whole table

Tags:

c#

asp.net

linq

I have a table of items using linq to entities, say:

ID | Name | Attb1 | Attb2
1 | Apple | Green | Juicy
2 | Orange | Orange | sweet

etc

I have another list with just ID's in it.

Using Linq I want to return all fields from the item table except where the ID is in the list. i.e. if my list just has '1' in it I want to return 2 | orange | orange | sweet

like image 527
Gordon Copestake Avatar asked Dec 18 '25 14:12

Gordon Copestake


1 Answers

You could try something like this

var result = table.Where(x => !list.Contains(x.id));

where I have assumed that table holds all the rows of your table and list contains the ids that you want to exclude.

like image 55
Christos Avatar answered Dec 21 '25 06:12

Christos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!