Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k 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 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...