November 8th, 2009Converting From System.Data.Linq.Binary to String and Back
Just a quick post in case anyone is wasting 10 minutes figuring out how to do this. For me, this came up because in Sql Server 2008, NVARCHAR(MAX) is 4000 characters and I needed more. The recommended datatype to use for more is VARBINARY. When I did that, LINQ2SQL converted that type to Linq.Binary. (using encoding)
So, in my C# code, here is what you need to convert to the Linq.Binary:
Linq.Binary carrierMatrix =
new ASCIIEncoding().GetBytes(myString);
And, to go back from Linq.Binary:
string carrierMatrixString = Encoding.ASCII.GetString(carrierMatrix.ToArray());
Hope this help!









February 1st, 2010 at 4:14 am
thank you so much. it really helped
September 15th, 2010 at 6:00 pm
Very cool. Worked perfectly.
December 1st, 2010 at 8:20 pm
[...] to this post for [...]
December 8th, 2010 at 5:32 am
one line of code…thankyou…
June 9th, 2011 at 11:22 pm
THANK YOU!
September 21st, 2011 at 5:30 am
thank you. code perfectly.