【发布时间】:2014-08-07 13:20:46
【问题描述】:
我有一个班级人员,其中有一个地址和电话列表作为以下代码。 在我的查询中,我想要一个人员列表,但不包括已删除的地址和电话,但始终返回所有地址和电话,即使它们标记为已删除。如何使用 lambda 过滤那些嵌套列表?
public class Person{
public int PersonId { get; set; }
public string Name { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual ICollection<Phone> Phones{ get; set; }
public virtual Company Company { get; set; }
}
public class Address{
public int AddressId { get; set; }
public string Street { get; set; }
public bool Deleted { get; set; }
[ScriptIgnore]
public virtual Person Person { get; set; }
}
public class Phone{
public int PhoneId { get; set; }
public string Number{ get; set; }
public bool Deleted { get; set; }
[ScriptIgnore]
public virtual Person Person { get; set; }
}
return GetDbSet<Person>()
.Include("Address")
.Include("Phones")
.Where(i => i.Company.CompanyId == company.CompanyId)
.OrderByDescending(o => o.CreateTime).ToList();
【问题讨论】:
标签: linq entity-framework lambda linq-to-entities