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
Post a Comment