I have 2 tables, Category and ProductToCategory.
Category has the name of all categories, and ProductToCategory has a list of all the categories assigned to a product. It is separated because 1 product can have multiple categories.
I am new to entity framework and am trying to get a list of categories that assigned to a specific product. I need to return the information from the Category table, but the ProductToCategory is where I search to get what is assigned.
I am trying to get all categories where the category ID is assigned to the specific product ID in the ProductTOCategory table.
In SQL I would type:
SELECT (Category Fields) FROM Category WHERE Category.Id
IN (SELECT ProductToCategory.CategoryId FROM ProductToCategory
WHERE ProductId = (THE PRODUCT ID))
Or something like that
Products.Find(10).Categories. That might end up with 2 calls to the database though, so you might want to do something like:Categories.Where(c => c.Products.Select(p => p.ProductId).Contains(10))Where(x => list.Contains(x))to generate theINclause.x in (...)translates to LINQ(...).Contains(x), you could try typing your SQL query in LINQ.