.net - Entity Framework select from link table with list -
using following database table structure:
order table:
orderid ordername
orderitem table:
orderid itemid
item table:
itemid itemname
i have 'order' entity has 'items' collection. need return orders contain items. example: orders items id: 1, 4 , 5 (i don't care if has other items well). have selected id's in list object (it doesn't have list though). have tried various ideas 'contains' method no avail.
because orderitem link table, can't access entity itself. if presumably do:
context.orderitems.where(m => selectedids.contains(m.itemid))
or that.
is there way of doing in single query without having loop around results?
thanks
context.orders.where(o => o.items.any(i => selectedids.contains(i.itemid)))
this requires ef 4.
Comments
Post a Comment