【发布时间】:2011-02-17 11:12:54
【问题描述】:
我有一个类似下面的模型:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Order> Orders { get; set; }
}
public class Order
{
public int Id { get; set; }
public DateTime DateTime { get; set; }
public Customer Customer { get; set; }
public ICollection<OrderLine> OrderLines { get; set; }
}
public class OrderLine
{
public int Id { get; set; }
public Product Product { get; set; }
public int Price { get; set; }
public int Quantity { get; set; }
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public Category Category { get; set; }
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
我正在使用this infrastructure。
我的聚合根是客户、订单、产品。我没有在此处包含映射,因为它们是直截了当的。
var customers = unitOfWork.Customers.FindAll();
var orders = unitOfWork.Orders.FindAll();
var products = unitOfWork.Products.FindAll();
var query = ......
使用 LINQ,您将如何选择所有订购“饮料”类别产品的客户?
我在网上看到的所有示例都是非常基本的查询,没有什么高级的。
【问题讨论】:
-
您的产品没有分类信息。
-
产品对类别的引用在哪里?
标签: entity-framework entity-framework-4 code-first ef-code-first entity-framework-ctp5