DevExpress XAF:获取子集合的集合

时间:2018-12-17 11:31:54

标签: devexpress xaf

我有3个班级:祖父,人,孩子

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 ...
}

现在,我想要的是,在祖父类中,我想获取与属于祖父的人相关的所有孩子的列表

例如:

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

因此,将XPCollection<Child>添加到班祖父中,其中将包含:Per1Ch1,Per1Ch2,Per2Ch1,Per2Ch2,并在可能的情况下提供排序选项。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用[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);
    }
}