首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DevExpress XAF:获取SubCollection集合

DevExpress XAF:获取SubCollection集合
EN

Stack Overflow用户
提问于 2018-12-17 19:31:54
回答 1查看 570关注 0票数 0

我有3个类: GrandFother,人,孩子

代码语言:javascript
复制
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 ...
}

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

例如:

代码语言:javascript
复制
GrangFother1 has two Persons: Person1, Person2.  
Person1 has 2 childs: Per1Ch1, Per1Ch2.    
Person2 has 2 childs: Per2Ch1, Per2Ch2

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

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-20 07:02:28

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

代码语言:javascript
复制
[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>通常就可以了。

代码语言:javascript
复制
[NonPersistent]
public IList<Child> GrandChildren
{
    get
    {
        return GFChilds
                  .SelectMany(x => x.Childs)
                  .OrderBy(x => x.Name);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53814367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档