Converting From System.Data.Linq.Binary to String and Back
Sunday 8 November 2009 @ 10:49 am

 

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!

 
Comments (1) - Posted in C#, LINQ, LINQ to SQL  




One Response to “Converting From System.Data.Linq.Binary to String and Back”

  1. farida Says:

    thank you so much. it really helped

Leave a Reply