0

为笨拙的标题道歉。我需要查询一个集合并根据孙子的属性返回祖父母、父母和孙子

例如,对于下面的对象,我只想在条件与计划的 ID 匹配时获取报价、费率(父)和计划(孙子)。

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; }
}
4

1 回答 1

4

你应该能够做这样的事情来获得符合任何标准的计划,以及他们的父母和祖父母对象:

// 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
    };
于 2012-05-22T20:22:30.977 回答