I have this linq to sql query:
var items =
from i in context.Items
orderby i.itemId descending
select new ItemWithCategories
{
item = i,
categories = (
from cats in context.categories
join ic in context.itemCategories
on cats.categoryId equals ic.categoryId
where ic.itemId == i.itemId
select cats).ToList()
};
It’s three tables. I need to join the categories with the items but there is a table in between (many-to-many). Is there a better to do this query ?
This yields the same results, but is much easier to read:
See how I removed the join statement, but using the
itemCategoriesproperty ofitem?