Best performance for find objects in entities and load entities, Foreach or where with LinQ ON C#?

ساخت وبلاگ

Vote count: 0

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.

asked 26 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : best performance for price car,best performance for overwatch,best performance for windows 10,best performance for price gpu,best performance for price cpu,best performance for the money car,best performance for price laptop,best performance for windows 7,best performance for fallout 4,best performance for cs go, نویسنده : استخدام کار backsoft بازدید : 285 تاريخ : سه شنبه 23 شهريور 1395 ساعت: 10:41