Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class User
  2. {
  3. public string Name { get; set; }
  4. public string Surname { get; set; }
  5. public int Age { get; set; }
  6. public string Country { get; set; }
  7.  
  8. // This comparer will be used to find records that exist or don't exist.
  9. public class KeyFieldComparer : IEqualityComparer<Person>
  10. {
  11. public bool Equals(User u1, User u2)
  12. {
  13. return u1.Name == u2.Name && u1.Surname == u2.Surname;
  14. }
  15.  
  16. public int GetHashCode(User u)
  17. {
  18. return u.Name.GetHashCode() ^ u.Surname.GetHashCode();
  19. }
  20. }
  21. }
  22.  
  23. List<User> csvList;
  24. List<User> oracleList;
  25.  
  26. // This will filter users that are in the CSV file that don't already exist in oracle.
  27. var newUsers = csvList.Except(oracleList, new User.KeyFieldComparer());
  28.  
  29. foreach (var newUser in newUsers)
  30. InsertNewUser(newUser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement