I have two lists.
- List of new categories that will be inserted into the database.
- List of categories that already exist in the database.
public class Category{ public string Name; } list<Category> dbCategories = new List(new Category{Name="John"}, new Category{Name = "Daniel"}, new Category{Name = "Matthew"}); list<Category> newCategories = new List(new Category{Name="John"}, new Category{Name="Rock"}, new Category{"Daniel"});
I want to prevent duplicates in the database based on Name
I fetch the categories list from the database. and now want to check if the list of new categories to be inserted have a matching name in the database categories.
- If the new categories have a name match in the database category list, I want to remove the category from the new Categories List that are to be inserted.
- I want to retrieve an Item matching Name, first search must be made on 1st List, If no match is found ,then 2nd List should be searched.
How do I achieve this?