Hi, I am trying to strongly type a query for 3 ef objects using linq to sql. There are one-to-many relationships with product and category. My classes contain navigation properties and look like this.
public partial class Product
{
public int ID {get;set;}
public string Name {get;set;}
public virtual ICollection<Group> NpGroup {get;set;}
}
public partial class Category
{
public int ID {get;set;}
public string Name {get;set;}
public virtual ICollection<Group> NpGroup {get;set;}
}
public partial class Group
{
public int ID {get;set;}
public int ProductID {get;set;}
public int CategoryID {get;set;}
public virtual Product NpProduct {get;set;}
public virtual Category NpCategory {get;set;}
}
Trying to avoid the string based .Include(), how would I construct a query that returned a group equal to ProductID "1" but also included the names of the product and category?
Something like:
var context = ObjectContext.CurrentObjectContext;
var query = from c in context.Group
where c.ProductID == 1
//Include the names of the product and category of the group record (c.NpProduct.Name etc.)
select c;
I am probably missing the trees through the forest but I can not seem to get the syntax of ObjectContext.LoadProperty (if that is the right way to go).
Any thoughts? Thanks.