Share via


Format Enum

Definition

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

public enum class Format
public enum Format
type Format = 
Public Enum Format
Inheritance
Format

Fields

Name Value Description
Unknown 0

The serialization format is unknown.

Native 1

This 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 .NET class libraries (such as String), are not supported.

UserDefined 2

This serialization format gives the developer full control over the binary format through the Write(BinaryWriter) and Read(BinaryReader) methods.

Examples

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.

using Microsoft.Data.SqlClient.Server;
using System.Data.SqlTypes;
using System.Text;

[Serializable]
[Microsoft.Data.SqlClient.Server.SqlUserDefinedType(Format.Native,
     IsByteOrdered = true,
     Name = "Point", ValidationMethodName = "ValidatePoint")]
public struct Point : INullable
{

Remarks

This enumeration is used by SqlUserDefinedTypeAttribute and SqlUserDefinedAggregateAttribute to indicate the serialization format of a user-defined type (UDT) or aggregate. Use of the Native and UserDefined enumeration members has special requirements.

  • Format.Native The requirements for the Format.Native format are:

    • The StructLayoutAttribute with a Value property value of LayoutKind.Sequential 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 (with a StructLayoutAttribute.Value of LayoutKind.Explicit).

  • Format.UserDefined The requirements for the Format.UserDefined format are:

Applies to