USER-DEFINED TYPES AND AGGREGATES There are two steps

USER-DEFINED TYPES AND AGGREGATES There are two steps in creating a user-defined type. The first is to create an assembly that contains the implementation of the user-defined type. This can be done using any language that the CLR supports. The second step is to add the assembly and the user-defined type to a database. The assembly is added to the database using the CREATE ASSEMBLY command, as was shown in Chapter 2. The user-defined type can then be added to the database by the CREATETYPEcommand, as shown in Listing 5-1. Note that user-defined types, unlike the built-in scalar types that SQL Server provides, must be specifically added to every database that requires them. Implementing a User-Defined Type The implementation of a user-defined type is a CLR class. The CLR classes are divided between reference types and value types. The principle difference between these two kinds of classes is how memory for instances of them is managed. The memory allocated for a reference type is always a pointer to a sequence of bits that is, a pointer to an object. The memory allocated for a value type is a sequence of bits that is, the object itself. There is no difference between these kinds of classes in the treatment of methods. Operationally, the semantics of parameter passing is different between them, and depending on usage, one may have a greater impact on performance or resource usage. Both the MSDN documentation and the Common Language Infrastructure Partition I discuss the differences between these. Either can be used to implement a user-defined type. Both C# and VB.NET use the classkeyword to define a CLR reference type class. C# uses the struct keyword, and VB.NET uses the Structure keyword to define the CLR value type class. We will use a structto implement LDim. The following code is a skeleton of the CLR class that we will use to implement LDim. This skeleton meets the basic requirement that a user-defined type be a CLR class. namespace UDT { // struct is used to define a CLR value type class public struct LDim … { // implementation … } }

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

Bookmark the permalink.

Comments are closed.