.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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -