Sau khi bạn đã thêm các loại, bạn có thể sử dụng nó giống như bất kỳ loại SQL Server bản địa khác. Ví dụ, bạn có thể tạo một bảng cơ sở dữ liệu mới với lệnh sau đây: CREATE TABLE DBMovies (ID INT IDENTITY, Phim DBMovie) | 924 CHAPTER 19 Building Data Access Components with Creating the User-Defined Type After you have loaded the DBMovie assembly you can create a new user-defined type from the assembly. Execute the following command CREATE TYPE EXTERNAL NAME If you need to delete the type you can execute the following command DROP TYPE DBMovie After you have added the type you can use it just like any other SQL Server native type. For example you can create a new database table with the following command CREATE TABLE DBMovies Id INT IDENTITY Movie DBMovie You can insert a new record into this table with the following command INSERT DBMovies Movie VALUES Star Wars George Lucas Finally you can perform queries against the table with queries like the following SELECT Id Movie FROM DBMovies WHERE SELECT MAX FROM DBMovies SELECT Movie FROM DBMovies WHERE LIKE g I find the fact that you can execute queries like this truly amazing. Building a Data Access Layer with a User-Defined Type In this final section let s actually do something with our new user-defined type. We create a new data access component that uses the DBMovie class and an page that interfaces with the component. Before we can do anything with the DBMovie type we need to add a reference to the assembly to our application. In Visual Web Developer select Website Add Reference and browse to the . Alternatively you can create an application root Bin folder and copy the into the Bin folder. Our new data access component is contained in Listing . LISTING App Code using System using using using using From the Library of Wow eBook Building Database Objects with the .NET Framework 925 public class DBDataLayer private static readonly string _connectionString public List DBMovie .