Object-Relational Mapping

While ADO.NET allows a certain degree of abstraction between databases, at its heart it mirrors the database structure. You use a database Connection object that accesses a command that either returns data in the form of a DataReader or populates a DataSet. You work with stored procedures or the database tables to maintain your database. However, as many developers discover, the data types used in the various databases are not the same, and they definitely do not match the data types you use in your Visual Basic applications. This can lead to errors in your application, such as when a database NULL is passed to a Visual Basic type. In addition, some of the interactions may be clumsy, such as when saving the contents of an object to the database, where you may need to map properties to the data in one or more database rows or tables.

To solve this object-to-database mismatch, a number of strategies have been developed. Many developers struggle with this process manually, handwriting a data access layer to convert between .NET and SQL. Another common strategy — and one requiring less work — is to use tools known as Object-Relational Mapping (ORM) tools. These tools either manually or automatically map the data types used in a database to those used by the client program, and vice versa. The best of these enable the actual structure of the database to be hidden from the client program, providing a more natural interaction between the program and the database. In the .NET world, the oldest and most used is nHibernate, itself a port of the Hibernate library developed first for Java development. However, there are many other ORMs, including SubSonic, LightSpeed, OpenAccess, and now Microsoft's Entity Framework. Even LINQ to SQL could be viewed as an ORM, in that it converts between Visual Basic types and SQL types.

While still a relatively young framework, the Entity Framework provides many of the capabilities available in the older, more mature frameworks. This includes the capability to split an object across multiple tables, map multiple objects to the same table, perform “lazy loading” (a performance optimization whereby an object is not loaded into memory until it is actually accessed), and much more. In addition, Microsoft is likely to continue to improve it over time, so it is definitely a strong competitor in the ORM space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset