devexpressxafxpo

DevExpress eXpressApp Framework and eXpress Persistent Objects : Sort column issue


I am not able to sort column for NonPersistent column. (DevExpress eXpressApp Framework (XAF) and eXpress Persistent Objects (XPO) ) Here my code

[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);
}

Now properties

[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")); }
    }

IF use PersistentAlias on NonPersistent column then I can able to sort this column. For that, I need to add logic on PersistentAlias.

In My Case:

I need to add this logic on PersistentAlias like [PersistentAlias('whole logic')]

LOgic

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

Let focus on logic

I have use AllAllotments (this not Association properties).

If I use like [PersistentAlias('use AllAllotments')] then I got error.

But I use like [PersistentAlias("use PCs")] then working.

Only different: PCs (Association properties) and AllAllotments (not Association ).

SO, MY Question:

How I can use AllAllotments on PersistentAlias ?

Anyone idea?


Solution

  • You can use a free join. From the DevExpress docs.

    With XPO, you can build criteria based on persistent objects that are not directly related (don't have explicitly defined associations) using Free Joins. In essence, XPO allows you to join any persistent objects on a condition, calculate aggregate functions against matching objects using their properties, and return aggregate values as the result of joining. To accomplish this, use JoinOperands in your criteria.

    You can either use them in criteria, e.g.,

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

    Or you can use them within [PersistentAlias]. See 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;
            }
        }
    }
    

    With all things DevExpress, the best place to ask is their support center.