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. ...

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.