endrec
asked on
How to use LINQ or Lambda expressions to update matching items in two generic lists?
Hello,
I wanted to find out if there is an "efficient" way to find all matching items in one generic list them update items in another generic list using a filter criteria.
Example: There is a list of customers and some customers having a missing first name and last name. In another list there is a listing of customer details that will sometimes contain the first name and last name for some of the customers with missing info from the first list.
How could I loop through or find only the items in list 1 where the customer first name and customer last name is null and update the first name and last name values with customer first name and customer last name values from list 2 if the commonality between the lists is not Id but address, city, and state? Is there a way that is most efficient to do this that is not a series of nested loops?
var filteredCustomerList1 = customerlist1.FindAll(c => c.FirstName == null && c.LastName == null)...
I wanted to find out if there is an "efficient" way to find all matching items in one generic list them update items in another generic list using a filter criteria.
Example: There is a list of customers and some customers having a missing first name and last name. In another list there is a listing of customer details that will sometimes contain the first name and last name for some of the customers with missing info from the first list.
How could I loop through or find only the items in list 1 where the customer first name and customer last name is null and update the first name and last name values with customer first name and customer last name values from list 2 if the commonality between the lists is not Id but address, city, and state? Is there a way that is most efficient to do this that is not a series of nested loops?
var filteredCustomerList1 = customerlist1.FindAll(c => c.FirstName == null && c.LastName == null)...
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The query finds the elements that have a matching address, but where FirstName and LastName are null. The foreach does the actual updating, in conjunction with a lambda to grab the matching record from list2.