c# - select matching object twice in a linq where-in clause -


i know can use contains method in generating where clause in linq query this:

list<long> objectids = new list<long>() { 1, 1, 2 }; var objects = dbcontext.where(o => objectids.contains(o.id))                      .select(o => o).tolist(); 

my question is, how able select matching object twice if id occurs twice in where condition?

it sounds want select separate copy of object each match.

select() can return 1 object; need selectmany():

list.selectmany(p => enumerable.repeat(p, objectids.count(id => id == p.id))) 

you faster using join.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -