Format Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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 |
Unknown | 0 | The serialization format is unknown. |
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 theFormat.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 theFormat.UserDefined
format are:The aggregate must specify a value for
MaxByteSize
.Specify the SqlUserDefinedTypeAttribute.IsByteOrdered attribute property. The default value is
false
.If you omit any field in the IBinarySerialize.Read or IBinarySerialize.Write methods, the state of that field is not serialized.