Sort EntityView on a related field

Posts   
 
    
JRF
User
Posts: 4
Joined: 13-Nov-2008
# Posted on: 13-Nov-2008 19:39:04   

LLBL version: 2.5 Final Database: SQL

I am attempting to manage a related collection of an entity in-memory so that I do not have to save the parent entity every time the user adds/removes an association. I have created an EntityView out of the collection so that I can issues a predicate expression to filter out entities in the related collection, and had hoped to be able to sort the EntityView on a field that is related to the collection. Is it possible to sort a collection(view) in-memory by a related field?

Here is an example of my code: ReportConfigurationCollection reportConfig = this.CurrentStateToConfigure.ReportConfigurationCollectionViaReportConfiguration_State;

            PredicateExpression selectExp = new PredicateExpression();
            selectExp.Add(new FieldCompareValuePredicate(ReportConfigurationFields.ReportID, ComparisonOperator.Equal, ApplicationConstants.BT_GRANT_REPORTID));
            selectExp.Add(new FieldCompareValuePredicate(ReportConfigurationFields.IsFA, ComparisonOperator.Equal, "True"));

            SortExpression sorter = new SortExpression();
            sorter.Add(new SortClause(BFYFields.BFY, SortOperator.Ascending));
            sorter.Add(new SortClause(CANFields.CAN, SortOperator.Ascending));

            EntityView<ReportConfigurationEntity> configurations = new EntityView<ReportConfigurationEntity>(reportConfig);
            configurations.Filter = selectExp;
            configurations.Sorter = sorter;

            this.gvFAConfig.DataSource = configurations;
            this.gvFAConfig.DataBind();

The Sorter does not do anything to the EntityView, nor does it throw an exception.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Nov-2008 21:35:34   

What is the relationship between BFY and CAN ?
Does your reportConfig collection contain pre-fetched related entities ?

JRF
User
Posts: 4
Joined: 13-Nov-2008
# Posted on: 13-Nov-2008 22:08:18   

Yes it does.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Nov-2008 04:52:36   
David Elizondo | LLBLGen Support Team
JRF
User
Posts: 4
Joined: 13-Nov-2008
# Posted on: 18-Nov-2008 19:47:55   

daelmo wrote:

Look at this: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=14681&StartAtMessage=0&#81865

This is similar to what I am attempting to do. I would like to filter and sort an in-memory collection by related fields. The only part of that thread that I don't understand is there is a MemberPredicate, as well as how do you get to the related fields from the OrderEntity. Is this example for the adapter or self-servicing scenario? I am using self-servicing for my implementation.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Nov-2008 05:23:13   

The thing is that you can't use EntityRelations when filtering in-memory on an EntityCollection (through EntityViews). So the MemberPredicate resolve this. Other thing you can do is filtering on a related custom property written by you, or on a field mapped on relations (set at LLBLGen designer). And last but not least, you can use LinqToObjects to filter the collection in-memory. In that post are examples of each on of above approaches (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=14681&StartAtMessage=0&#81828).

David Elizondo | LLBLGen Support Team
JRF
User
Posts: 4
Joined: 13-Nov-2008
# Posted on: 19-Nov-2008 16:01:31   

I was able to figure out a solution using the "fields mapped on relations" in the LLBL designer, and then just referencing the related field by string. Thanks for your help!