Sort EntityView on a related field

Posts   
 
    
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 25-Jun-2009 18:27:50   

LLBLGEN 2.6 ORM Support classes version 2.6.09.0305

Problem : After defining a field on related field ( 1:1 relation ship - the field is a string) and using the LLBLGENDataSource2 (adapter), I am getting an ORMInterpretationException : The expression has just 1 operand and the operand is null when trying to use the e.Sorter in the PerformSelect event. It only happens when trying to sort by the related field and not the other ones. The exception is thrown in the code segment that is highlighted in green. I have checked the sorter and it has the correct sort expression in it.

Thanks, Brandt




        protected void DS_CurrentSchedules_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
        {
            if (this._pageController.Item != null)
            {
                var col = this._pageController.Item.CurrentOnCallScheduleCollection;
                [colorvalue="00CC00"]col.Sorter = e.Sorter;[/color]
                foreach (var ent in col)
                {
                    e.ContainedCollection.Add(ent as EntityBase2);
                }
            }
        }


    public partial class ContactGroupEntity
    {

        public EntityView2<OnCallScheduleEntity> CurrentOnCallScheduleCollection
        {
            get 
            {
                return new EntityView2<OnCallScheduleEntity>(OnCallScheduleCollection, OnCallScheduleFields.EndDate > DateTime.Now);
            }
        }

        public EntityView2<OnCallScheduleEntity> PastOnCallScheduleCollection
        {
            get
            {
                return new EntityView2<OnCallScheduleEntity>(OnCallScheduleCollection, OnCallScheduleFields.EndDate < DateTime.Now);
            }
        }
    }




daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jun-2009 20:13:47   

Hi Brandt,

What is on e.Sorter when it fails? Is the related collection prefetched (there are items in the 1:1 related entity).

David Elizondo | LLBLGen Support Team
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 25-Jun-2009 20:16:33   

daelmo wrote:

Hi Brandt,

What is on e.Sorter when it fails?

Is the related collection prefetched (there are items in the 1:1 related entity).

It is has a sortexpression with an entityfield and a descending sortorder. The entityfield has the correct name MemberName.

The related collection is prefetched.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jun-2009 20:53:41   

Please try using EntityProperty when sorting on related entities. (more info...).

Example:

ISortExpression sorter = new SortExpression();
sorter.Add(new EntityProperty("EmployeeName") | SortOperator.Ascending);

EntityView2<OrderEntity> ordersView = new EntityView2<OrderEntity>(orders);
ordersView.Sorter = sorter;
David Elizondo | LLBLGen Support Team
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 26-Jun-2009 14:40:37   

daelmo wrote:

Please try using EntityProperty when sorting on related entities. (more info...).

Example:

ISortExpression sorter = new SortExpression();
sorter.Add(new EntityProperty("EmployeeName") | SortOperator.Ascending);

EntityView2<OrderEntity> ordersView = new EntityView2<OrderEntity>(orders);
ordersView.Sorter = sorter;

Ok that helped lead me to a solution. The LLBLGENDataSource2 had to be set to client side sorting and then it worked. Thanks