为笨重的头衔道歉。我需要查询一个集合并根据孙子的属性
返回祖父母,父母和孙子女例如,如果条件与计划的ID匹配,我想获得报价,汇率(父)和计划(GrandChild)。
public class Quote
{
public int Id { get; set; }
public string Type { get; set; }
public string ParentType { get; set; }
public decimal ValueMax { get; set; }
public virtual ICollection<Rate> Rates { get; set; }
}
public class Rate
{
public int Id { get; set; }
public decimal ValueMax { get; set; }
public ICollection<Plan> Plans { get; set; }
}
public class Plan
public int Id { get; set; }
public decimal Price { get; set; }
}
答案 0 :(得分:3)
你应该能够做这样的事情来获得满足任何标准的计划,以及他们的父母和祖父母对象:
// results is an anonymous type with properties Quote, Rate, Plan
var results = from q in quotes
from r in q.Rates
from p in r.Plans
where p.Id < 500 /* whatever criteria */
select new
{
Quote = q,
Rate = r,
Plan = p
};