Exception using SortExpression generated via DbFunctionCall for EntityView

Posts   
 
    
Posts: 77
Joined: 05-May-2005
# Posted on: 25-Jun-2010 18:22:54   

LLBLGenPro version: 2.6 Final (October 9, 2009) File Version on SupportClasses DLL: 2.6.09.0903 Using Self Servicing with .NET 3.5 and SqlServer 2005

Code in question:

    // construct custom sort expresssion
    // (sorts by bytes 10 and 11 of LabelDescription field)
    object[] substringParameters = { SettingsFields.LabelDescription, 10, 2 };
    DbFunctionCall substringCall = new DbFunctionCall("SUBSTRING", substringParameters);
    EntityField sortField = new EntityField("ServiceSortOrder", substringCall);
    SortClause serviceSortOrderClause = new SortClause(sortField, null, SortOperator.Ascending);
    serviceSortOrderClause.EmitAliasForExpressionAggregateField = false;
    SortExpression sorter = new SortExpression(serviceSortOrderClause);
    
    // resort and project collection
    SettingsCollection inSvcSettings = (SettingsCollection)InSvcSettingsDataSource.EntityCollection;
    [colorvalue="FF0000"][b]// exception occurs on the next statement[/b][/color]
    EntityView<SettingsEntity> inSvcSettingsView =
        new EntityView<SettingsEntity>(inSvcSettings, sorter);
    List<IEntityPropertyProjector> propertyProjectors = 
        EntityFields.ConvertToProjectors(inSvcSettings.EntityFactoryToUse.CreateFields());
    SettingsCollection inSvcSortedSettings = new SettingsCollection();
    inSvcSettingsView.CreateProjection(propertyProjectors, inSvcSortedSettings); 

Exception text:
   The expression object set for entity field 'ServiceSortOrder' isn't implementing IExpressionInterpret

Stack Trace:
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityFieldCore.SD.LLBLGen.Pro.ORMSupportClasses.IEntityFieldCoreInterpret.GetValue(IEntityCore entity)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.SortIndices(List`1 listToSort, ISortExpression sorter, Int32 indexInSortExpression)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.SetSorter(ISortExpression sorter)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.InitClassCore(CollectionCore`1 relatedCollection, IPredicate filterToApply, ISortExpression sorterToApply, PostCollectionChangeAction dataChangeAction)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityView`1..ctor(EntityCollectionBase`1 relatedCollection, IPredicate filter, ISortExpression sorter, PostCollectionChangeAction dataChangeAction)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityView`1..ctor(EntityCollectionBase`1 relatedCollection, ISortExpression sorter)
   at SbsController.UI.MfcParametersForm.PageSpecificOk() in B:\\jkelly_laptop_SbsController_view\\sdnyct\\sbsController\\src\\ui\\MfcParametersForm.aspx.cs:line 202"  string

Is it not possible to use this kind of custom sort with an entity view? Is there an alternate way to sort this collection in memory and project to another collection?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jun-2010 22:09:34   

Try this:

SortClause serviceSortOrderClause = new SortClause(sortField | SortOperator.Ascending)
David Elizondo | LLBLGen Support Team
Posts: 77
Joined: 05-May-2005
# Posted on: 28-Jun-2010 13:07:16   

This statement does not compile: Error 1 'SD.LLBLGen.Pro.ORMSupportClasses.SortClause' does not contain a constructor that takes '1' arguments

I tried: SortClause serviceSortOrderClause = new SortClause(sortField, SortOperator.Ascending);

I got the same error message.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Jun-2010 15:00:29   

Strange!!

try this: IEntityField sortField = new EntityField("ServiceSortOrder", substringCall); SortClause serviceSortOrderClause = new SortClause(sortField, SortOperator.Ascending);

Posts: 77
Joined: 05-May-2005
# Posted on: 28-Jun-2010 16:27:21   

I still get the same exception.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jun-2010 07:27:35   

Are you sure that with the following line of code:

SortClause serviceSortOrderClause = new SortClause(sortField, SortOperator.Ascending);

You get the following exception:

Error 1 'SD.LLBLGen.Pro.ORMSupportClasses.SortClause' does not contain a constructor that takes '1' arguments

Coz it seems it's complaining about another line SortClause CTor, which is receiving one parameter only.!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jun-2010 07:28:01   

I think it's obvious but I didn't see it before. Remember that EntityView is a class which is used to create in-memory views on an entity collection. The entity collection is already fetched so you are working only with in-memory data and you are actually trying to use a DBFunctionCall which is a call to a function in database engine, that is why the exception.

Since you are using .Net3.5 wouldn't be difficult to create a Linq2Objects query to project yor desire result using .Net functions.

Regards,

David Elizondo | LLBLGen Support Team