Sorting using function

Posts   
 
    
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 03-Apr-2009 16:14:05   

Hi all I'm trying to make something like that


SELECT * FROM CODE
ORDER BY GET_FIRST_TRANSLATION(CODE.TP_ID, 1)

quite simple ... but I can't do it so .. is it possible in llblgen ? How ?

I tried this

EntityCollection<Code> ec = new EntityCollection<Code>();
SortExpression se = new SortExpression();

EntityField2 field = CodeFields.TpId;
field.ExpressionToApply = new DbFunctionCall("GET_FIRST_TRANSLATION", new object[] { 1 });
se.Add(field | SortOperator.Ascending);
this.Context.Adapter.FetchEntityCollection(ec, null, 0, se);

It create this SQL:

SELECT ... FROM [HRANEW_NUNITTEST_DEV].[dbo].[CODE] ORDER BY [TpId] ASC

So there isn't any call to the db function rage

Does anyone have an idea ? Tx for your help simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Apr-2009 21:22:02   

Hi Fab, Please try this:

EntityCollection<Code> ec = new EntityCollection<Code>();
SortExpression se = new SortExpression();

// set my dbfunction at the sorter clause
EntityField2 field = CodeFields.TpId;
field.ExpressionToApply = new DbFunctionCall("GET_FIRST_TRANSLATION", new object[] { 1 });
SortClause sc1 = new SortClause(field, SortOperator.Ascending);
sc1.EmitAliasForExpressionAggregateField = false;
se.Add(sc1);

// fetch
this.Context.Adapter.FetchEntityCollection(ec, null, 0, se);
David Elizondo | LLBLGen Support Team
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 06-Apr-2009 09:59:49   

Where come the property "EmitAliasForExpressionAggregateField" from ? Because it seem this property isn't know:


EntityCollection<Code> ec = new EntityCollection<Code>();
SortExpression se = new SortExpression();

IEntityField2 field = CodeFields.TpId;
field.ExpressionToApply = new DbFunctionCall("GET_FIRST_TRANSLATION", new object[] { 1 });
SortClause sc = new SortClause(field, null, SortOperator.Ascending);
sc.EmitAliasForExpressionAggregateField = false;
se.Add(sc);
this.Context.Adapter.FetchEntityCollection(ec, null, 0, se);

And on compilation:

Error   4   'SD.LLBLGen.Pro.ORMSupportClasses.SortClause' does not contain a definition for 'EmitAliasForExpressionAggregateField'

I'm in 2.5 version

Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 06-Apr-2009 10:15:44   

I saw this post http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=15167&HighLight=1 So there isn't any way to do it in 2.5 ? I'll not change the llblgen version 2 weeks before a release frowning )

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 06-Apr-2009 10:37:36   

In your case, as you're so close to release, it's best perhaps to download the v2.5 and v2.6 runtime library sourcecode archives from the customer area. Then please look at the SortExpression.ToQueryText methods. The v2.6's has a check on the property added to SortClause mentioned by David above. Add the property to the v2.5's SortClause class and add the differences to the v2.5's version of SortExpression.ToQueryText. I've to look into the changelogs but I think it's probably the only change between the two, so you also might want to simply copy over v2.6's SortExpression class and use that instead. Then build a new runtime lib using your own strong key. (remove any DQE project of databases you don't need).

Then reference in your project the new ormsupportclasses and DQE. You've to change the references as you've build the ormsupportclasses dll with a new strong key.

Frans Bouma | Lead developer LLBLGen Pro
Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 06-Apr-2009 15:11:04   

Ok thanks for the tip

I think I'll do the sort in code, in the process. If it's too slow, I''ll use your advice and recompile the llblgen library. But I'm always a bit nervous to change the data layer on a pre-prod release simple_smile But I think that as it's a new module not yet sold to a lot of customer, it'll not be massively used. So I don't expect to have a lot of data soon, so I think the perf will be acceptable. And then after, for the next version, I'll upgrade to 2.6 and change to use in-db sort.

I ll try this path, thanks a lot for your help !