Format Format Format Format Enum


SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute 用来指示用户定义类型 (UDT) 或聚合的序列化格式。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


Native Native Native Native 1

此序列化格式使用非常简单的算法,以便于 SQL Server 能够在磁盘上存储 UDT 的高效表示形式。This serialization format uses a very simple algorithm that enables SQL Server to store an efficient representation of the UDT on disk. 标记为 Native 序列化的类型只能将值类型(在 Microsoft Visual C# 中为 struct,在 Microsoft Visual Basic .NET 中为 structure)用作成员。Types marked for Native serialization can only have value types (structs in Microsoft Visual C# and structures in Microsoft Visual Basic .NET) as members. 不支持引用类型(如 Visual C# 和 Visual Basic 中的类)的成员,无论是用户定义的成员,还是 .NET 类库中的现有成员(如 String)。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.

Unknown Unknown Unknown Unknown 0

该序列化格式是未知的。The serialization format is unknown.

UserDefined UserDefined UserDefined UserDefined 2

使用此序列化格式,开发人员可以通过 Write(BinaryWriter)Read(BinaryReader) 方法完全控制二进制格式。This serialization format gives the developer full control over the binary format through the Write(BinaryWriter) and Read(BinaryReader) methods.


下面的示例演示UserDefinedTypePoint UDT 属性。The following example shows the UserDefinedType attribute of the Point UDT. UDT 是字节顺序,名为"点",其名为"ValidatePoint"的验证方法并使用本机序列化格式。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
<Serializable(), SqlUserDefinedTypeAttribute(Format.Native, _
  IsByteOrdered:=True, _
  Name:="Point", _
  ValidationMethodName:="ValidatePoint")> _
  Public Structure Point
    Implements INullable


此枚举由SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute以指示用户定义类型 (UDT) 或聚合的序列化格式。This enumeration is used by SqlUserDefinedTypeAttribute and SqlUserDefinedAggregateAttribute to indicate the serialization format of a user-defined type (UDT) or aggregate. 利用NativeUserDefined枚举成员都有特殊要求。Use of the Native and UserDefined enumeration members has special requirements.

  • Format.Native

    对于要求Format.Native格式是:The requirements for the Format.Native format are:

    • StructLayoutAttributeValue属性值为LayoutKind.Sequential必须应用于聚合或如果它一个类,而不是结构中定义的 UDT。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 使用此属性确定具有多个字段的 Udt 的字段顺序。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).

    • 聚合的所有字段必须都是blittable; 也就是说,它们必须在托管和非托管内存中具有共同的表示形式并不需要进行特殊处理互操作封送处理程序。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.

    • UDT 的所有字段应都为可序列化的以下类型之一: boolbytesbyteshortushortintuintlongulongfloat``doubleSqlByteSqlInt16SqlInt32SqlInt64SqlDateTimeSqlSingleSqlDoubleSqlMoney,或包含的其中一个字段的用户定义的其他值类型类型。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.

    • 聚合必须指定为值MaxByteSizeThe aggregate must not specify a value for MaxByteSize.

    • 聚合不能有 [NonSerialized] 的任何字段。The aggregate must not have any [NonSerialized] fields.

    • 字段不能标记为显式布局 (与StructLayoutAttribute.ValueLayoutKind.Explicit)。Fields must not be marked as an explicit layout (with a StructLayoutAttribute.Value of LayoutKind.Explicit).

  • Format.UserDefined

    对于要求Format.UserDefined格式是:The requirements for the Format.UserDefined format are: