OK, first off, I'm brand new to LINQ2SQL so excuse my ignorance.
I've done some searches, but after 1 hour, I decided to come here.
Here goes:
I'm trying to do something that I think is very simple. It could just be that I don't understand. I'm using LINQ 2 SQL, via the VS designer. I have 2 tables: Clients and Categories. A client can have multiple categories.
I have a very simple query to find clients:
Client c = db.Clients.SingleOrDefault(client => client.ID == id);
What I want to do is modify this so that the collection: c.Categories, will only contain a subset of that client's categories.
This is what I've tried:
Client c = db.Categories.Where(cat => cat.IsActive == true).Select(cat.Clients).SingleOrDefault(client => client.ID == id);
I get an error reporting that more than one client is being returned.
- Am I missing something? Is this not something that LINQ is designed to do?
Am I supposed to use the first query then do another query specifically on Categories when I need that list??
c.Categories.Categories.Where(cat => cat.IsActive == true)
Thank you in advance.