- How to check-not add duplicates with EF from a list
- foreach (var item in so)
- {
- context.ORDERS.AddObject(item);
- }
- db.SaveChanges();
- foreach (var item in so)
- {
- //If ORDERS List doesn't contain any item with the same id
- //or any other predicate match
- if(!context.ORDERS.Any(o => o.Id == item.Id)) //or any other property of item
- context.ORDERS.AddObject(item);
- }
- db.SaveChanges();