Sorting an EntityView on a related tables field.

Posts   
 
    
wokket
User
Posts: 1
Joined: 11-Feb-2010
# Posted on: 11-Feb-2010 04:52:51   

G'day guys,

LLBLGen 2.6 Final .Net 3.5 SP1 Self-Servicing Model Oracle 10g r2

Apologies in advance for the long class names in here

I have an entity (HardwareChannelDefaultEntity) containing a collection of ChannelDefaultEntity's.

I'm returning an EntityView of this collection to filter out obsoleted items etc

/// <summary> /// Gets the active Hardware Available Columns. /// </summary> /// <value>The active data category states.</value> public EntityView<ChannelDefaultEntity> ActiveChannelDefaults { //Because we can mark child objects as deleted well prior to them actually being saved // we'll provide a filtered view of that data for binding/validation etc get { if (_activeChannelDefaults == null) {

                var predicate = PredicateHelper.GetStandardPredicate(new ChannelDefaultEntity(), false);
                _activeChannelDefaults = (EntityView<ChannelDefaultEntity>)ChannelDefault.CreateView(predicate, null);
                _activeChannelDefaults.DataChangeAction = PostCollectionChangeAction.ReapplyFilterAndSorter;

            }

            return _activeChannelDefaults;
        }
    }

And everything works perfectly. simple_smile

Each of those ChannelDefaultEntity's has an n:1 relationship with a ChannelTemplateEntity.

I can sort the returned data by fields on the ChannelDefaultEntity easily enough, by adding a sorter to the call to CreateView:

ISortExpression sorter = new SortExpression(ChannelDefaultFields.Code | SortOperator.Ascending); _activeChannelDefaults = (EntityView<ChannelDefaultEntity>)ChannelDefault.CreateView(predicate, sorter);

However I need return the data sorted by a field on related ChannelTemplateEntity, specifically ChannelTemplateFields.ChannelNo.

Altering the sorter to the following: ISortExpression sorter = new SortExpression(ChannelTemplateFields.ChannelNo | SortOperator.Ascending);

Results in the colelction being returned as if there was no sorter specified. I attempted to add a Field On Related Field, but as there is no EntityField generated for this, it can't be used for sorting.

I considered sorting the EntityView myself prior to returning it to the user, but was unable to see a suitable method (maybe I'm blind!).

Any help on sorting an EntityView on a related field's field?

If you'd like any more info, please just reply and I'll post it ASAP.

Cheers, Tim

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-Feb-2010 11:22:59   

Add a field on a related field,or directly add a property which returns thi related entity's field value, and then use a sorter as follows.

var sorter = new SortExpression(new EntityProperty("ChannelNo") | SortOperator.Ascending);