我有3个类: GrandFother,人,孩子
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类中,我想要获得与属于祖父的人相关联的所有孩子的列表
例如:
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,如果可能的话,还可以使用排序选项。
谢谢。
发布于 2018-12-20 07:02:28
您可以使用[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);
}
}https://stackoverflow.com/questions/53814367
复制相似问题