Export (0) Print
Expand All

Format Enumeration

Used by SqlUserDefinedTypeAttribute and SqlUserDefinedAggregateAttribute to indicate the serialization format of a user-defined type (UDT) or aggregate.

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)

public enum Format

Member nameDescription
NativeThe Native serialization format uses a very simple algorithm that enables SQL Server to store an efficient representation of the UDT on disk. Types marked for Native serialization can only have value types (structs in Microsoft Visual C# and structures in Microsoft Visual Basic .NET) as members. Members of reference types (such as classes in Visual C# and Visual Basic), either user-defined or those existing in the framework (such as String), are not supported.

The requirements for this format are:

  • The StructLayout.LayoutKindSequential attribute must be applied to the aggregate or UDT if it is defined in a class and not a structure. This controls the physical layout of the data fields, and is used to force the members to be laid out sequentially in the order they appear. SQL Server uses this attribute to determine the field order for UDTs with multiple fields.

  • The type must contain at least one member (serialized values cannot be zero bytes in size).

  • All the fields of the aggregate must be blittable, that is, they must have a common representation in both managed and unmanaged memory and not require special handling by the interop marshaler.

  • All the fields of the UDT should be of one of the following types that can be serialized: bool, byte,sbyte,short,ushort, int, uint, long, ulong, float, double, SqlByte, SqlInt16, SqlInt32, SqlInt64, SqlDateTime, SqlSingle, SqlDouble, SqlMoney, or other value types defined by the user that contain fields of one of these types.

  • The aggregate must not specify a value for MaxByteSize.

  • The aggregate must not have any [NonSerialized] fields.

  • Fields must not be marked as an explicit layout (StructLayoutAttribute).

UnknownThe serialization format is unknown.
UserDefinedThe UserDefined serialization format gives the developer full control over the binary format through the IBinarySerialize.Write and IBinarySerialize.Read methods.

The aggregate must specify a value for MaxByteSize.

Specify the IsByteOrdered attribute property. The default value is false.

If you omit any field in the Read or Write methods, the state of that field is not serialized.


The following example shows the UserDefinedType attribute of the Point UDT. The UDT is byte-ordered, is named "Point", has a validation method named "ValidatePoint", and uses the native serialization format.

     Name="Point",ValidationMethodName = "ValidatePoint")]
public struct Point : INullable

.NET Framework


.NET Framework Client Profile

Supported in: 4, 3.5 SP1



© 2014 Microsoft