0 out of 4 rated this helpful - Rate this topic

Binary Class

Represents an immutable block of binary data.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
[SerializableAttribute]
[DataContractAttribute]
public sealed class Binary : IEquatable<Binary>
System.Object
  System.Data.Linq.Binary
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
This type does not XmlSerialize
This type doesn't serialize so if you are planning to manually serialize an entity with say a timestamp you'll get an error during serialization initialization.
Convert to String

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));
}