DevExpress eXpressApp Framework和eXpress Persistent Objects:排序列问题

时间:2016-08-31 13:01:07

标签: devexpress xaf xpo

我无法为NonPersistent列排序列。 (DevExpress eXpressApp Framework(XAF)和eXpress Persistent Objects(XPO)) 这是我的代码

[Association("PCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> PCs
{
    get { return GetCollection<Allotments>("PCs"); }
}

[Association("SCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> SCs
{
     get { return GetCollection<Allotments>("SCs"); }
}

XPCollection<Allotments> _allAllotmentsCore;
public XPCollection<Allotments> AllAllotments
{
    get
         {
            if (_allAllotmentsCore == null)
               {
                _allAllotmentsCore = new XPCollection<Allotments>(Session);
               }
               _allAllotmentsCore.Criteria = CriteriaOperator.Parse("PCGrower.Oid == ? OR SCGrower.Oid == ?", Oid);
               _allAllotmentsCore.Sorting.Add(new SortProperty("Project.ProjectName", SortingDirection.Descending));

                PopulateCollection(_allAllotmentsCore);
                return _allAllotmentsCore;
        }
}

private void PopulateCollection(XPCollection<Allotments> sourceCollection)
{
            sourceCollection.AddRange(PCs);
            sourceCollection.AddRange(SCs);
}

现在属性

[PersistentAlias("PCs[Project is not null].Count")] // THIS IS WORKING
//[PersistentAlias("AllAllotments[PCs.Project is not null].Count")] // THIS IS NOT WORKING
 public int myCustomProperties 
    {
        get { return Convert.ToInt32(EvaluateAlias("myCustomProperties")); }
    }

如果在NonPersistent列上使用PersistentAlias,那么我可以对此列进行排序。为此,我需要在PersistentAlias上添加逻辑。

在我的案例中:

我需要在PersistentAlias上添加这个逻辑,例如[PersistentAlias(&#39;整个逻辑&#39;)]

逻辑

public int myCustomProperties 
    {
                get
                {
                    int _myCustomProperties  = 0;
                    Projects project = null;
                    foreach (Allotments obj in AllAllotments)
                    {
                        if (project != obj.Project && obj.Project != null)
                        {
                            project = obj.Project;
                            _myCustomProperties += 1;
                        }
                    }
                    return _myCustomProperties  ;
                }
    }

让我们专注于逻辑

我使用AllAllotments(这不是关联属性)。

如果我使用[PersistentAlias(&#39;使用AllAllotments&#39;)]那么我就会收到错误。

但我使用[PersistentAlias(&#34;使用PC&#34;)]然后工作。

只有不同:PC(关联属性)和AllAllotments(非关联)。

所以,我的问题:

如何在PersistentAlias上使用AllAllotments?

有人想过吗?

1 个答案:

答案 0 :(得分:1)

您可以使用免费加入。来自DevExpress文档。

  

使用XPO,您可以基于持久对象构建标准   没有直接关系(没有明确定义的关联)   使用免费加入。从本质上讲,XPO允许您加入任何持久性   条件上的对象,计算聚合函数以防匹配   对象使用其属性,并返回聚合值作为   加入的结果。要完成此任务,请在您的帐户中使用JoinOperands   标准。

您可以在条件中使用它们,例如,

CriteriaOperator criteria = 
CriteriaOperator.Parse("[<Orders>][^.EmployeeID = EmployeeID].Count() > 50");
XPCollection<Employee> employees = new XPCollection<Employee>(session, criteria);

或者您可以在[PersistentAlias]内使用它们。请参阅this item from the DevExpress support center

public class Department : BaseObject 
{
     private System.Int32? _TotalPhoneNumbers;
     [PersistentAlias("[<PhoneNumber>][Party.<Contact>Department.Oid = ^.Oid and PhoneType='1'].Count()")]
     public System.Int32? TotalPhoneNumbers {
        get {
            if (_TotalPhoneNumbers == null) {
                _TotalPhoneNumbers = (int?)EvaluateAlias("TotalPhoneNumbers");
            }
            return _TotalPhoneNumbers;
        }
    }
}

对于所有DevExpress,最好的问题是support center