Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare id's of objects in two lists and get the list of objects that includes objects with ids occurring in both of them

I have struggled with it for a long time. I have two collections: MyRepository.All and MyCollection, both holds the collection of objects which has ID property. I need to get result of list of objects from MyRepository.All what contains only objects which id's are equal to MyCollection's objects'ids.

ICollection MyCollection // as parameter to method

var result = MyRepository.All.Where(r=>r.id==MyCollection.???.id).ToList();

i need to replace ??? with some linq to get this done. ive tried different where and select caluses, excist and intersect and so on..

like image 488
Marek Avatar asked Dec 09 '22 11:12

Marek


1 Answers

from a in MyRepository.All
join m in MyCollection on a.Id equals m.Id
select a
like image 50
dav_i Avatar answered Dec 11 '22 06:12

dav_i