I have such database structure (1 – one, 0 – many)
Product 1->0 Orders 0->1 Users
I need to find all users for specified product, I have started writing linq query but don’t know how to finish it.
public IQueryable<User> GetUsers(int productId)
{
return _db.Products.First(p => p.Id == productId)....
}
First things first, the
Firstmethod will only return the first item that meets your criteria, and since you want to return anIQueryableofUsers, this is probably not what you want.Second, I think the easiest way to get started with Linq-to-SQL is to use query notation, especially when you’re dealing with joins, which don’t look too pretty when using lambda expressions.