I have two list different types (because they represents two different types in two different databases):
public partial class PersonOne
{
public int id { get; set; }
public string name { get; set; }
public string surname { get; set; }
public string address { get; set; }
public string phone { get; set; }
}
public partial class PersonTwo
{
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string email { get; set; }
}
I want to eliminate duplicates with the same firstname and lastname on the List and then take from that list objects which have got different firstname and lastname than objects on the List. Firstname in the class PartTwo = name in the class PartOne and lastname in the class PartTwo = surname in the class PartTwo.
I have that code but it is very slow:
List<PersonOne> personOneList = new List<PersonOne>(); // very big list
List<PersonTwo> personTwoList = new List<PersonTwo>(); // very big list
List<PersonTwo> difference = personTwoList
.GroupBy(x => new { FirstName = x.firstname.ToLower(), LastName = x.lastname.ToLower() })
.Select(x => x.First())
.Where(x => !personOneList.Any(y => y.name.Equals(x.firstname, StringComparison.InvariantCultureIgnoreCase) && y.surname.Equals(x.lastname, StringComparison.InvariantCultureIgnoreCase)))
.ToList();