How can linq to sql force convert ntext column to nvarchar (max) in generated sql?

Below was the problem when I was looking for a solution for a couple of hours. I finally found it and wanted to share it so I can save other people wasting time with it.

I have a query in linq to sql that needs to be sorted and grouped by a column whose type is ntext. Sorting or grouping by ntext column calls . Text, ntext, and image data types cannot be compared or sorted, except when using the IS NULL or LIKE operator. ... Before sorting or grouping data, the data must be cast into nvarchar. How can I instruct linq to sql to dump the ntext column to nvarchar (max) column?

+1


source to share


1 answer


The call to Convert.ToString ("Value") caused the column values ​​to be other than ntext to nvarchar (max) and the resulting sql was CONVERT (NVarChar (max), Value) . Sorting and grouping worked fine then.



+3


source







All Articles