Hi,
Im fairly new to Linq and struggling using dynamic where over a many to many relationship.
Database tables are like so:
Products <-> Products_SubCategories <-> SubCategories
with Products_SubCategories being a link table.
My full linq statement is
db.Products.Where("it.SubCategories.SubCategoryID = 2")
.Include("SubCategories")
.OrderBy(searchOrderBy)
.Skip(currentPage * pageSize)
.Take(pageSize)
.ToList()
.ForEach(p => AddResultItem(items, p));
So ignoring everything bar the Where() Im here just trying to pull out all products which are linked to sub category ID 2, this fails with
To extract properties out of collections, you must use a sub-query to iterate over the collection., near multipart identifier, line 8, column 1.
I think using the SQL-esque syntax i can do a sub-querry as per this link. However im not sure how to do that in the lambada / chaining synatax?
This is the start of a search function and i would like to build up the where string dynamically, as i have with the "searchOrderBy" string to avoid a large SELECT CASE. Products is linked to another table via a link table that i will need to include once i understand how to do this example.
Any help would be much appreciated!
Thanks