Given the following classes:
class Order
{
public int Id;
public string OrderNumber;
public DateTime OrderDate;
}
class OrderItem
{
public int Id;
public int OrderId;
public string ProductName;
public decimal Price;
}
class OrderComment
{
public int Id;
public int OrderId;
public string Subject;
public string Message;
}
and the following DataContext
public interface IDataContext
{
IQueryable<Order> Orders{get;}
IQueryable<OrderItem> OrderItems{get;}
IQueryable<OrderComment> OrderComments{get;}
}
How would you go about building a Linq query that will create an Order graph with its details (items & comments) as shown below:
class OrderDetails
{
public int Id;
public string OrderNumber;
public DateTime OrderDate;
public IList<OrderItem> Items;
public IList<OrderComment> Comments;
}
Note: We want to hit the database only once.