Compare ntext by row in sql server 2005 by linq

How to compare ntext type in sql server 2005 with string with linq?

in SQL Server 2005

@a as ntext

linq in C #;

string b;

var k=from p in DataContext.TableName 

where p.a.toString()==b)

select p;

//return k=null
+3
source share
3 answers

NTEXT columns cannot be compared. See MSDN and MSDN Forum

If you work in 2005 or higher, convert NTEXT to NVARCHAR (MAX), as others have already pointed out.

+1
source

You can do this in linq2sql using the static "Like" method of the System.Data.Linq.SqlClient.SqlMethods class.

string b;

var k=from p in DataContext.TableName 

where System.Data.Linq.SqlClient.SqlMethods.Like(p.a, b)

select p;
+1
source

linq2sql, - .ToString() , , .

, , NVARCHAR (MAX) NTEXT

0

All Articles