IMPLEMENTING A USER-DEFINED TYPE Instances of user-defined types,

IMPLEMENTING A USER-DEFINED TYPE Instances of user-defined types, just like any other scalar type, are saved to and read from disk as a stream of bytes. For all user-defined types, this stream of bytes can be no larger than 8,000 bytes. SQL Server needs to know how much space is required on disk for an instance of a user-defined type and what code to use to read and write the byte stream that is saved on the disk. SQL Server also needs to know whether or not it can be ordered according to the byte stream that is stored on disk for it. The SqlUserDefinedTypeAttributeused on a CLR class definition for a user- defined type provides this information. This is shown in the following code fragment. namespace UDT { // properties of SqlUserDefinedType describe to SQL Server // how to save and order an LDim [SqlUserDefinedType(...)] public struct LDim … { // implementation … } } The SqlUserDefinedTypeAttribute has a property named Format. When the Format property is set to System.Data.Sql.Format.Native, SQL Server provides the code that is used to read and write the byte stream. There are a number of requirements of a class that uses the Native setting of the Format attribute the class must use the StructLayout Attribute with its Value property set to LayoutKind.Sequential; all fields in the CLR class must be blittable; and the class must have a SerializableAttribute attribute. For example, a class that has a field of type string may not have the Format property of the SqlUserDefined TypeAttributeset to Native. The MSDN documentation enumerates the CLR classes that are blittable. In essence, only value types that have the same physical representation in the CLR as they do in the native operating system are blittable. The MSDN documentation specifically lists System.Byte, System.SByte, System.Int16, System.UInt16, System.Int32, System.UInt32, System. Int64, System.UInt64, System.IntPtr, System.UIntPtr, and any one- dimensional array of the types previously listed as being blittable. In addition to these, a Format.Native user-defined type may also use System. Float, System.Double, SqlSingle, SqlDouble, SqlByte, SqlInt16,

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Bookmark the permalink.

Comments are closed.