使用Linq获取相关的儿童用品?

时间:2016-11-09 08:36:58

标签: c# entity-framework linq

我有这些实体:

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IEnumerable<Order> Orders { get; set; }
}

public class Order
{
    public int Id { get; set; }
    public int CustomerId { get; set; }
    public Category Category { get; set; }
}

public class Category
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class CustomerOrder
{
    public int Id { get; set; }
    public string Name { get; set; }
    //Some other properties here...
    public IEnumerable<Order> Orders { get; set; }
}

我正在使用Linq来获取客户及其订单如下:

var customers = dataContext.Set<Customer>();

return (from customer in customers
        where customer.Id == id
        select new CustomerOrder
        {
          Id = id,
          Name = customer.Name,
          Orders = customer.Orders
        });

以上项目如预期。但是,我需要为每个Category检索Order

如何通过扩展上述Linq语句来实现此目的?

0 个答案:

没有答案