DevExpress XAF:获取子集合的集合

DevExpress XAF: Get Collection of SubCollection

我有 3 个 Classes : GrandFother, Persons, Child

public class GrandFother: BaseObject
{
[Association("GrandFother_Persons")]
//......
public XPCollection<Persons > GFChilds
{
   get
    {
        return GetCollection<Persons >("GFChilds");
    }
}
}

public class Persons: BaseObject
{
[Association("Persons_Childs")]
// Other code ...
public XPCollection<Child> Childs
{
   get
    {
        return GetCollection<Child>("Childs");
    }
}
//Other code ...
}

public class Child: BaseObject
{
[Association("Persons_Childs")]
// Code ...
}

现在,我想要的是,在 class GrandFother 中,我想获取与属于 Grandfother

的 Persons 关联的所有 Childs 的列表

例如:

GrangFother1 has two Persons: Person1, Person2.  
Person1 has 2 childs: Per1Ch1, Per1Ch2.    
Person2 has 2 childs: Per2Ch1, Per2Ch2

因此,将 XPCollection<Child> 添加到 Class Grandfother 中,它将包含:Per1Ch1、Per1Ch2、Per2Ch1、Per2Ch2,如果可能的话还有排序选项。

谢谢。

您可以使用 [NonPersistent] 集合 属性。

[NonPersistent]
public XPCollection<Child> GrandChildren
{
    get
    {
        var result = new XPCollection<Child>(Session, GFChilds.SelectMany(x => x.Childs));

        // sorting
        SortingCollection sortCollection = new SortingCollection();
        sortCollection.Add(new SortProperty("Name", SortingDirection.Ascending));
        xpCollectionPerson.Sorting = sortCollection;

        return result;
    }
}

但您可能不需要 XPCollection<Child> - IList<Child> 通常就可以。

[NonPersistent]
public IList<Child> GrandChildren
{
    get
    {
        return GFChilds
                  .SelectMany(x => x.Childs)
                  .OrderBy(x => x.Name);
    }
}