select from list not containing particular item in linq

Hector

I have two class.

public class Category
{
   public int Id {get;set;}
   public string Name{get;set;}
}
public class Product
{
   public int ProductId{get;set;}
   public string Name{get;set;}
   public List<Category> ProductCategory {get;set;}
}

Now i have Category list based on that i need to get product

List<string> filtercategory ={"HomeMade","Uncooked"}.

I need to all Products which doesn't belong to 'HomeMade' and 'Uncooked'.

What should be linq query logic on this?

thanks.

René Vogt

You can simply filter with Where:

List<Product> productList = GetProducts();
var filteredProducts = productList
                         .Where(p => p.ProductCategory
                                      .All(pc => !filtercategory.Contains(pc.Name)))
                         .ToList();

This filters the productList and takes only those products for which all category names are not contained in filtercategory.


I only tested this in linq-to-sql, not with entities, so I'm not 100% sure that this also works for entities.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to randomly select an item from a list?

From Dev

how to get specific list from database on onclick of a particular item in listview

From Dev

LINQ select Top 1 from List<T>

From Dev

Linq - Select list of tags from a list objects, each containing a list of tags

From Dev

Moq a retrieve of particular list item

From Dev

Linq - Select a particular column

From Dev

Linq select from list

From Dev

Remove a specific item from a list using LINQ

From Dev

Most Pythonic Way to Select Particular Tuple from List of Tuples

From Dev

How select an item from dropdown list in angularjs?

From Dev

Using LINQ, how would you filter out all but one item of a particular criteria from a list?

From Dev

Remove item from a list on second select

From Dev

LINQ select List where sub-list contains item from another list

From Dev

Select last wrong item from the list

From Dev

Linq get specific item from list of lists

From Dev

Select specific item from list

From Dev

How to select a particular list item from a list? (like the sixth or second etc.)

From Dev

Linq - Select list of tags from a list objects, each containing a list of tags

From Dev

Linq - choosing item or a default from a list

From Dev

Linq query select a particular value from xml

From Dev

How to get rows from a list containing each couple of value in LINQ?

From Dev

using LINQ to get a particular set of objects from a list of objects

From Dev

Using LINQ, how would you filter out all but one item of a particular criteria from a list?

From Dev

Select properties for particular entities LINQ

From Dev

Select last wrong item from the list

From Dev

How to group particular fields from the list using linq

From Dev

Select a particular element in a webpage from list using selenium python

From Dev

Refresh particular item in the list view

From Dev

Select item from a list based on an array

Related Related

  1. 1

    How to randomly select an item from a list?

  2. 2

    how to get specific list from database on onclick of a particular item in listview

  3. 3

    LINQ select Top 1 from List<T>

  4. 4

    Linq - Select list of tags from a list objects, each containing a list of tags

  5. 5

    Moq a retrieve of particular list item

  6. 6

    Linq - Select a particular column

  7. 7

    Linq select from list

  8. 8

    Remove a specific item from a list using LINQ

  9. 9

    Most Pythonic Way to Select Particular Tuple from List of Tuples

  10. 10

    How select an item from dropdown list in angularjs?

  11. 11

    Using LINQ, how would you filter out all but one item of a particular criteria from a list?

  12. 12

    Remove item from a list on second select

  13. 13

    LINQ select List where sub-list contains item from another list

  14. 14

    Select last wrong item from the list

  15. 15

    Linq get specific item from list of lists

  16. 16

    Select specific item from list

  17. 17

    How to select a particular list item from a list? (like the sixth or second etc.)

  18. 18

    Linq - Select list of tags from a list objects, each containing a list of tags

  19. 19

    Linq - choosing item or a default from a list

  20. 20

    Linq query select a particular value from xml

  21. 21

    How to get rows from a list containing each couple of value in LINQ?

  22. 22

    using LINQ to get a particular set of objects from a list of objects

  23. 23

    Using LINQ, how would you filter out all but one item of a particular criteria from a list?

  24. 24

    Select properties for particular entities LINQ

  25. 25

    Select last wrong item from the list

  26. 26

    How to group particular fields from the list using linq

  27. 27

    Select a particular element in a webpage from list using selenium python

  28. 28

    Refresh particular item in the list view

  29. 29

    Select item from a list based on an array

HotTag

Archive