I have two set of lists and I want to create one list with unique values and other with existing if stockNumber
and supplierName
matches. So that I can do Update/Insert operation accordingly.
My criteria are:
- if number and name matches in list1 and list2 then it will be part of existingRecords list
- else move them to newRecords list
Current List:
var existingSuppliers = _dbContext.Supplier
.Where(_ => _.Id.Equals(existingException.Id)).ToList();
var currentSuppliers = exception.Suppliers
.ToLookup(x => x.SupplierName).Select(g => g.First()).ToList();
I tried with Except
and Intersect
but looks like I am not doing this right.
If I do:
var intersect = existingSuppliers.Intersect(currentSuppliers).ToList(); // returns 0
var except = existingSuppliers.Except(currentSuppliers).ToList(); // returns existingSuppliers (1 records)
And if I do other way:
var intersect2 = currentSuppliers.Intersect(existingSuppliers).ToList(); // 0 records
var except2 = currentSuppliers.Except(existingSuppliers).ToList(); // currentSupplier (2 records)