【发布时间】:2010-12-23 10:45:33
【问题描述】:
使用 Entity Framework 4 CTP5 我有一个基本模型和一个可以工作的基本 DbContext
public class Customer {
public int CustomerId { get; set; }
public int Name { get; set; }
//...
public ICollection<Address> Addresses { get; set; }
public bool HasAddress {
get {
return Addresses.Count > 0;
}
}
}
public class Address {
public int AddressId { get; set; }
public string StreetLine1 { get; set; }
//....
public Customer Customer { get; set; }
}
如何查询我的 DbContext 以返回所有客户以及他们是否有地址?
一个客户可以有多个地址,当我只对他们是否有地址感兴趣时,我不想返回每个客户的所有地址。我用
context.Customers.Include(c => c.Addresses) 但返回每个客户的所有地址
【问题讨论】:
标签: entity-framework linq-to-entities