Varchar (max) + linq to sql

I have varchar (max) which I am trying to read, but the field is truncated by 4000 characters. I saw similar questions , but they are on sql side.

What do I need to do to get the whole field?

For instance:

using (DataContext dc = new DataContext()) { var foo = dc.foos.First(); if (foo.Formula2.Length > 4000) { Console.WriteLine("success!"); } } 

I tried things like setting TextSize , but that didn't affect it .:

 dc.ExecuteCommand("SET TEXTSIZE 100000;"); var foo = dc.foos.First(); 

UPDATE:

The server data type is varchar (max). The field in question is formula 2: alt text

If I try to change the type to something other than Object, I get the message "Mapping between DbType" VarChar (MAX) "and" Type "System.Object in the Formula 2 column of type" t_PriceFormula "is not supported.

Any suggestions?

+4
source share
2 answers

From thanks to 888 .

It seems a bit confusing, but it worked.

Convert the field to an array, then go back to the string.

 var foo = dc.foos.First(); string formula = new string(foo.Formula2.ToArray()); 
+3
source

it sounds like .net convert varchar to nvarchar I don't know how to solve it. but System.Text.Encoding may help try this

 //1 set col in db to varbinary(max) //2 and when u want to save to db string formula = "..."; System.Data.Linq.Binary bin = new System.Data.Linq.Binary(System.Text.Encoding.ASCII.GetBytes()); //3 when u pull ou Binary bin = row.Formula2; string formula = System.Text.Encoding.ASCII.GetString(bin.ToArray()); 
+2
source

All Articles