Linq to SQL 错误:按表达式排序只能包含非常量标量 [英] Linq to SQL error : An order by expression can only contain non-constant scalars

查看:13
本文介绍了Linq to SQL 错误:按表达式排序只能包含非常量标量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 GridView 和 LinqDataSource 来查看 Categories 表.我设置了 Gridview 以启用排序.排序通常有效,除非我点击了描述"列的标题.

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.

order by 表达式只能包含服务器可比较的非常量标量.'NText' 类型的表达式不是订单可比较的."

"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."

描述是用 ntext 转换的,但有人可以向我解释发生了什么吗?为什么 NText 在 nvarchar 是不可排序的?

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

推荐答案

SQL Server 只是不允许您按 NText 字段订购(另请参阅 SQL Server 错误列表).我的猜测是出于效率原因,但我不能肯定.

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.

现在链接文章中的解决方案被转换为 nvarchar...但这显然在 LINQ 中很难做到.

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

您的描述字段是否一定需要是 ntext?

Does your description field definitely need to be an ntext?

这篇关于Linq to SQL 错误:按表达式排序只能包含非常量标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆