C# 急于加载嵌套实体
我将以下内容保持得非常简单:C# 急于加载嵌套实体,c#,linq,entity-framework,C#,Linq,Entity Framework,我将以下内容保持得非常简单: public class Customer { public int Id {get; set} public IEnumerable<Reminder> Reminders {get; set} public IEnumerable<Order> Orders {get; set} } public class Reminder { public int CustomerId {get; set}
public class Customer
{
public int Id {get; set}
public IEnumerable<Reminder> Reminders {get; set}
public IEnumerable<Order> Orders {get; set}
}
public class Reminder
{
public int CustomerId {get; set}
public string Text {get; set}
}
public class Order
{
public int CustomerId {get; set}
public int CategoryId {get; set}
}
public class OrderDetails
{
public int OrderId {get; set}
public int ProductId {get; set}
}
但是上面提到的一切。如果我执行以下操作,将引发异常:
var customer = customerRepository.Get(10, x => x.Reminders, x => x.Orders.Where(c => c.CategoryId == categoryId).Select(o => o.OrderDetials));
那么,我如何才能真正只退回我需要的订单呢?我很确定,目前EF无法做到这一点。从MSDN中注意,目前无法筛选加载的相关实体。包含将始终存在于所有相关实体中。来源:加载客户后,如何仅检索我需要的订单,因为一旦检索到客户,订单集合将为空。
var customer = customerRepository.Get(10, x => x.Reminders, x => x.Orders.Select(o => o.OrderDetails));
var customer = customerRepository.Get(10, x => x.Reminders, x => x.Orders.Where(c => c.CategoryId == categoryId).Select(o => o.OrderDetials));