Q: Can I store my business objects in SQL Server 2005 using CLR user-defined types?
A: Implementing a SQL CLR user-defined type (UDT) is very simple, like giving. NET class or struct to add some extra fragments. These include attributes (SqlUserDefinedTypeAttribute), interfaces (inullable), and some additional methods (Null () and Parse ()). The consequence of this simplicity is that an experienced developer can convert a business object into a SQL CLR user-defined type in less than 5 minutes.
The design goal of SQL Server 2005 is not for object-oriented database management systems. It is also a standard SQL database management system, and the ability of user-defined types should also be treated as a type of system extension, not an object. Developers should carefully weigh their choices when deciding whether to use existing business objects as CLR UDT.
Each time a method or property of an instance of a type is accessed, the instance should be serialized before the method is accessed. Therefore, it is best to rely on those comparable types based on their serialized bytes. Developers should try to use only those user-defined types that can answer questions automatically. For example, the following C # class is less than a user-defined type:
class Product
{
public string Name;
public string Description;
public decimal price;
}
If a query is for such a type of field, each row must be drag to answer the following question, "What product is worth 10 dollars?" This is because we cannot assume that all 10 dollars of products have the same binary representation. Drag of each row in a large table, such as a table with millions of products, can be a serious test of performance.
In addition to the performance challenges, there are also standardization issues. For example, suppose this type, how can a company store two descriptions for the same product, and make sure that there is only one valid price for the product?
It is best to stick to types that can answer questions and do not bring drag to the line.