Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

database - Linq to SQL error : An order by expression can only contain non-constant scalars

I'm using a GridView and a LinqDataSource to view the Categories table. I set the Gridview to enable sorting. Sorting generally works except when i clicked on the header of the Description column.

"An order by expression can only contain non-constant scalars that are order comparable by the server. The expression with type 'NText' is not order comparable."

Description is casted with ntext but can someone explain to me what's happening? why does NText is not sortable when nvarchar are?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SQL Server just doesn't let you order by NText fields (see also error 420 in the SQL Server Error List). My guess is that it's for efficiency reasons, but I couldn't say for sure.

Now the solution in the linked article is cast to nvarchar... but that's obviously pretty hard to do in LINQ.

Does your description field definitely need to be an ntext?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...