1

I want to create, update and delete records from two data sources, a CSV file and a database.

Each items are loaded in a specific model :

List<Employee> fromEmployees = this.loadCSVEmployees();
List<Employee> toEmployees = this.loadDBEmployees();

And I use Except and Intersect to compares values :

List<Employee> empToDelete = toEmployees.Except(fromEmployees, new EmpEqualityComparer()).ToList();
List<Employee> empToCreate = fromEmployees.Except(toEmployees, new EmpEqualityComparer()).ToList();
List<Employee> empToUpdate = fromEmployees.Intersect(toEmployees, new EmployeeIntersetComparer()).ToList();

empToUpdate contain the values I want to update (so from fromEmployees) but the ID of the records is set in the toEmployees list.

What is the best method to merge some values (like the identity) from the two list on the intersect result ? The employee model has a SSNO I use to know identical users... I cant use union.

Jerome
  • 603
  • 2
  • 5
  • 15
  • The `Intersect` will return matching records on the 2 lists, so could you not just switch it to `toEmployees.Intersect(fromEmployees, <...>)`? – Canica Aug 06 '19 at 20:54
  • Because Intersect match only some properties like the SSNO and return the CSV result... switching return the SGBD results... – Jerome Aug 06 '19 at 20:58
  • What's the question here? The title is a vague list of keywords, not really a question. Merging objects has been asked quite often. For instance [merging two objects in C#](https://stackoverflow.com/q/8702603/215552). But I'm not sure that's what you want to do... – Heretic Monkey Aug 06 '19 at 20:58
  • I'm not entirely sure what you are trying to do but `Zip` or `Join` may be very useful – BradleyDotNET Aug 06 '19 at 21:04
  • Just know If a linq method other like Union exist... Using reflexion like your link is not really a perfect way... – Jerome Aug 06 '19 at 21:04
  • 1
    Who said anything about reflection? – BradleyDotNET Aug 06 '19 at 21:07
  • What's not working for you and _how_? – Aluan Haddad Aug 06 '19 at 21:13

1 Answers1

0

You can use .Zip to provide a projection (like .Select) function, but you'll need to filter your two source lists separately instead of using .Intersect and make sure both lists are in identical order before feeding them into .Zip.

Jeff Shepler
  • 2,007
  • 2
  • 22
  • 22