Binary Class
Represents an immutable block of binary data.
Assembly: System.Data.Linq (in System.Data.Linq.dll)
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
- 7/15/2009
- Rick Strahl [old]
If you are using ASP.Net and use the SQL Server "timestamp" datatype for concurrency, you may want to convert the "timestamp" value into a string so you can store it (e.g., on a web page). When LINQ to SQL retrieves a "timestamp" from SQL Server, it stores it in a Binary class instance. So you essentially need to convert the Binary instance to a string and then be able to convert the string to an equivalent Binary instance.
The code below provides two extension methods to do this. You can remove the "this" before the first parameter if you prefer them to be ordinary static methods. The conversion to base 64 is a precaution to ensure that the resultant string contains only displayable characters and no escape characters.
public static string ConvertRowVersionToString(this Binary rowVersion) {
return Convert.ToBase64String(rowVersion.ToArray());
}
public static Binary ConvertStringToRowVersion(this string rowVersion) {
return new Binary(Convert.FromBase64String(rowVersion));
}
- 8/7/2008
- John M Paliwoda