Sorting on a DbFunctionCall

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 10-Jun-2009 22:12:32   

LLBLGen Version 2.6 Final. Adapter Templates.

I have two date fields I want to sort by, a Start Date and an End Date. I want to sort only by the date portion and ignore the time portion. The time portion should not be considered so when two records have the same StartDate date part, they will be sorted by the EndDate.

For Example:

Default behavior - Sort By (StartDate ASC, EndDate ASC)


Id  StartDate                   EndDate
1   Jan 1 2009 1:00PM   Mar 1 2009 1:00PM
2   Jan 1 2009 2:00PM   Feb 1 2009 1:00PM

Desired Behavior - Sort By (DatePartOnly(StartDate) ASC, EndDate ASC)


Id  StartDate                   EndDate
2   Jan 1 2009 2:00PM   Feb 1 2009 1:00PM
1   Jan 1 2009 1:00PM   Mar 1 2009 1:00PM

I was able to do this using by applying an Expression in a ResultsetFields and sorting on that field, but this seems a little hackish and requires me to get my results as a list.

Is it possible to do the same thing but more closely to how the "Generated code > Calling a database function > Using a function call in a predicate" example in the documentation works? I tried applying the expression to a field and passing it along with the sorter, but it gets ignored. Or is there another way which I have overlooked?

Posts: 112
Joined: 09-Aug-2004
# Posted on: 10-Jun-2009 22:39:02   

I searched all over the forum I and didn't see an answer, perhaps because I was searching with terms related to dates. I just saw this thread eight threads down

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15954

which brought me to this thread

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14331

which brought me to this property

EmitAliasForExpressionAggregateField

This solved my problem!