Sort by ntext field fails - can I cast it as nvarchar?

Posts   
 
    
kbscan
User
Posts: 2
Joined: 05-Feb-2008
# Posted on: 05-Feb-2008 10:46:07   

.NET 2.0 MS SQL Server 2000 LLBLGen Pro. Version: 1.0.2004.2 Final (June 10th, 2005)

I have this query:

SELECT * FROM QuestionType
INNER JOIN Text ON Text.id = QuestionType.TextId
ORDER BY lid2

That fails because lid2 is ntext.

This on the other hand works fine:

SELECT * FROM QuestionType
INNER JOIN Text ON Text.id = QuestionType.TextId
ORDER BY CAST(lid2 as nvarchar)

So the question is, how do I write the code, so it fits my working query statement?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Feb-2008 11:33:58   

I recommend not sorting on an nText field even if casted, as this would be a major performance hit, IMHO.

Anyway, using v. 1.0.2004.2 try to derive your own SortExpression from the SortExpression class and then override the ToQueryText to emit expression needed.

kbscan
User
Posts: 2
Joined: 05-Feb-2008
# Posted on: 05-Feb-2008 13:46:56   

I recommend not sorting on an nText field even if casted, as this would be a major performance hit, IMHO.

Thanks for the advice. Fortunately this query only returns 4 items and is run only when our webapp. starts, so I should be safe regarding performance.

Anyway, using v. 1.0.2004.2 try to derive your own SortExpression from the SortExpression class and then override the ToQueryText to emit expression needed.

Could you give some code example on this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 05-Feb-2008 13:54:22   

That's not going to work, SortExpression has a ToQueryText since v2.0.

I'd suggest to sort on the client if you want to sort just 4 items. (so sort teh entities in the collection)

Frans Bouma | Lead developer LLBLGen Pro