2

Below problem had me look for a solution for couple of hours. I finally found it and wanted to share so I can save other people spending time on it.

I have a query in linq to sql that needs to sort and group by on a column whose type is ntext. Sorting or grouping on ntext column causes “The text, ntext and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.” Before sorting or grouping takes place, the data needs to be casted into nvarchar. How can I instruct linq to sql to cast my ntext column into nvarchar(max) column?

1 Answer 1

5

Calling Convert.ToString("Value") caused the column values to be casted from ntext to nvarchar(max) and resulting sql was CONVERT(NVarChar(max),Value). Then sorting and grouping worked just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.