I need to relate a few entities. Right now the code is loaded the first entity and then is iterated with a foreach loop and search on each record if the current row match with the property of the record of the other entity. Something like:
foreach (Entity1 e1 in entity1List)
{
foreach (Entity2 e2 in entity2List)
{
if (e2.Id == e1.Id)
{
//Do something
}
}
}
But the entities have a lot of records and the performance is not being good. I want to improve the speed trying to use linQ for search the record.
var list = entity2List.Where(e2 => entity1.Any(e1 => e1.Id == e2.Id));
foreach (Entity2 e2 in list )
{
//Do something
}
But I don't know if this is really helping for the performance. Also I would like to know the best model for load the entities in this case. Some advises or links for read, please.
