Custom Properties and Sorting

Posts   
 
    
DaveL
User
Posts: 5
Joined: 07-Nov-2006
# Posted on: 08-Nov-2006 20:54:40   

I have a table (named Location) that contains 3 columns - ID, Location, and LocationNewName. In the past(pre LLBLGen), I've used the sql COALESCE command to combine these columns into one value (If LocationNewName is null, then it returns the value for location).

I'm new to LLBLGen and am having difficulty duplicating this functionality through the provided classes. I've modified the LocationEntity class and added a new property called "LocationText" that will return the appropriate Location value. The problem that I am having is when I try to sort based on this new property.

The code I found in another thread is

Dim MySort As New SortExpression MySort.Add(New SortClause(New EntityProperty("LocationText"), SortOperator.Ascending)) LLBLGenProDataSource.SorterToUse = MySort

and I get the following error:

Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'.

Thanks, Dave

DaveL
User
Posts: 5
Joined: 07-Nov-2006
# Posted on: 08-Nov-2006 21:00:32   

Sorry - forgot to give versions, etc.

LLBLGen Pro 2.0.0 Final ASP.Net 2.0, Visual Studio 2005 Self Servicing

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 21:14:20   

EntityProperty is used for client-side sorting. SO you should set the SortingMode property to CLientSide, then you can sort on that property simple_smile

Frans Bouma | Lead developer LLBLGen Pro
DaveL
User
Posts: 5
Joined: 07-Nov-2006
# Posted on: 08-Nov-2006 21:22:12   

I've tried that as well and still get the same error.

<llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="MyProj.CollectionClasses.LocationsCollection, App_Code.zpal0u5b" SortingMode="ClientSide">

and also tried the following in Page_Load

LLBLGenProDataSource.SortingMode = DataSourceSortingMode.ClientSide Dim MySort As New SortExpression MySort.Add(New SortClause(New EntityProperty("LocationText"), SortOperator.Ascending)) LLBLGenProDataSource.SorterToUse = MySort

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 22:06:54   

What's the buildnr of the ormsupport classes? (see guidelines for details how to obtain that number)

(and what's that assembly name 'App_Code.zpal0u5b' doing there? It should have been 'MyProj'. Did you reference the generated code correctly in your webproject?

Frans Bouma | Lead developer LLBLGen Pro
DaveL
User
Posts: 5
Joined: 07-Nov-2006
# Posted on: 09-Nov-2006 14:58:48   

The version of the ORMSupportClasses.NET20.dll file is 2.0.0.61023

The strange assembly name was caused by placing the uncompiled classes in my APP_Code directory. I thought it would be easier to make customizations while developing that way. I've since tried the other way - compiling my generated classes and putting the dll file in the bin directory, and I get the same error.

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Nov-2006 18:31:20   

Thanks. I'll check it out to see if I can reproduce it and if so, fix it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 10-Nov-2006 11:02:04   

My bad, I should have looked more closely.

Change:


Dim MySort As New SortExpression
MySort.Add(New SortClause(New EntityProperty("LocationText"), SortOperator.Ascending))
LLBLGenProDataSource.SorterToUse = MySort

into:


Dim MySort As New SortExpression
MySort.Add(New SortClause(New EntityProperty("LocationText"), Nothing, SortOperator.Ascending))
LLBLGenProDataSource.SorterToUse = MySort

The thing is that EntityProperty implements IEntityFieldCore, and therefore has to use the constructor which accepts IEntityFieldCore.

Frans Bouma | Lead developer LLBLGen Pro
DaveL
User
Posts: 5
Joined: 07-Nov-2006
# Posted on: 10-Nov-2006 16:09:39   

That's fixed it - thanks for your help.

Dave