LLBLGenDataSource2 and Sorting

Posts   
1  /  2  /  3
 
    
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 30-May-2006 18:44:07   

Ok, a follow up - My DataSource is bound to an entity collection of type"ExamEntryEntity". If my initial sorter is an ExamEntryField then everything works fine.

However, if my initial sorter is based on a field from a different (but related) entity then it will not work when SortingMode is set to clientside (but it works fine for serverside).

Example:

My Data source


<CW:LLBLGenProDataSource2 runat="server" ID="dsStatement" AdapterTypeName="DataLibrary.DatabaseSpecific.DataAccessAdapter, DataLibraryDBSpecific"
    DataContainerType="EntityCollection" EntityFactoryTypeName="DataLibrary.FactoryClasses.ExamEntryEntityFactory, DataLibrary" SortingMode="clientSide">
</CW:LLBLGenProDataSource2>

Sorter that works:


SortExpression sorter = new SortExpression();
sorter.Add(ExamEntryFields.SubjectCode | SortOperator.Ascending);
dsStatement.SorterToUse = sorter;

Sorter that doesn't work:


dsInfo.FilterToUse = new RelationPredicateBucket();
dsStatement.FilterToUse.Relations.Add(ExamEntryEntity.Relations.SubjectEntityUsingSubjectCode);
SortExpression sorter = new SortExpression();
sorter.Add((SubjectFields.SubjectArea | SortOperator.Ascending));
dsStatement.SorterToUse = sorter;

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 31-May-2006 11:03:18   

Ok, this is logical: client side sorting uses sorting on the entityview(2) of the collection. So sorting that is sorting on the fields of the entity, not on a related entity. This thus explains why you won't see any sorting on a related entity's field when you use client-side sorting.

The reason sorting on a related entity's field works in the database is simply because the complete set of data right before the final columns are created does contain that field, so sorting that complete set is possible. However in-memory that's not the case, as the set of data to sort with is offered by the entities in the collection, not in a related entity or related entity of that related entity.

This is a current limit of the entityview(2) objects. It's for example also not possible to filter an entityview(2) object on a related entity or contents of a collection for example ('show only the customers which have orders'). I will spend some time thinking how to solve this though before the release but when I did try to get related entity filtering/sorting into the code, it was pretty cumbersome, as at runtime the code doesn't have any meta-data about relations and their property mapped onto that relation in a particular entity.

Frans Bouma | Lead developer LLBLGen Pro
Kjelli
User
Posts: 27
Joined: 11-May-2006
# Posted on: 04-Oct-2006 14:02:18   

I just tried to set SortingMode = Client to get sorting on related entities:

[ArgumentException: At least one object must implement IComparable.] System.Collections.Comparer.Compare(Object a, Object b) +156 System.Collections.Generic.ObjectComparer1.Compare(T x, T y) +38 System.Collections.Generic.ArraySortHelper1.QuickSort(T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer) +155

[InvalidOperationException: Failed to compare two elements in the array.] System.Collections.Generic.ArraySortHelper1.QuickSort(T[] keys, TValue[] values, Int32 left, Int32 right, IComparer1 comparer) +427 System.Collections.Generic.ArraySortHelper1.Sort(T[] keys, TValue[] values, Int32 index, Int32 length, IComparer1 comparer) +159 System.Collections.Generic.ArraySortHelper1.Sort(T[] items, Int32 index, Int32 length, IComparer1 comparer) +125 System.Array.Sort(T[] array, Int32 index, Int32 length, IComparer1 comparer) +144 System.Collections.Generic.List1.Sort(Int32 index, Int32 count, IComparer1 comparer) +93 System.Collections.Generic.List1.Sort() +15 SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase1.SortIndices(List1 listToSort, ISortExpression sorter, Int32 indexInSortExpression) +1020 SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase1.SetSorter(ISortExpression sorter) +99 SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase1.set_Sorter(ISortExpression value) +29 SD.LLBLGen.Pro.ORMSupportClasses.EntityView`1.SD.LLBLGen.Pro.ORMSupportClasses.IEntityView.set_Sorter(ISortExpression value) +29 SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelectEntityCollection(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) +1120 SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +251 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +153 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99 System.Web.UI.WebControls.GridView.DataBind() +23 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92 System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +33 System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +74 System.Web.UI.Control.PreRenderRecursiveInternal() +148 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.WebControls.WebParts.WebPart.PreRenderRecursiveInternal() +379 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4437

Am I missing something?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 04-Oct-2006 14:48:35   

PLease don't hijack a thread. See the guidelines http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7717 for the info you should provide for us so we can help you better. It looks like a NULL value issue, which I can't reproduce. Please provide the info as stated in the guidelines link posted above.

Frans Bouma | Lead developer LLBLGen Pro
1  /  2  /  3