We are a user experience design and software development firm
Hire us to design your site, build your application, serve billions of users and solve real problems.
I've been looking at some of the new features in the .NET 3.5 framework and have found Object Relation Mapping (ORM) very similar to IBatis.NET and NHibernate. In .NET 3.5, they use attribute based mapping between the underlying data table and entity class (Domain Object). For instance
using System.Data.Linq;
using System.Data.Linq.Mapping;
[Table="Books"]
public class Book {
[Column="Name"]
public string _Name;
[Column="ISBNNo"]
public string _isbn;
...
}
What you notice is the the class Book is mapped to a table called Books using the Table attribute and particular table columns are mapped using the column attribute on the Book class instance fields. Compared with IBatis.NET XML files; you would have to:
<sqlMap namespace="Surveys" xmlns="http://ibatis.apache.org/mapping">
<alias>
<typeAlias alias="Book" type="Namespace.Books, AssemblyName"/>
</alias>
<resultMaps>
<resultMap id="BookMap" class="Book">
<result property="Name" column="Name"/>
<result property="ISBN" column="ISBN"/>
</resultMap>
</resultMaps>
<statements>
<select id="GetBooks" parameterClass="map" resultMap="BookMap">
select name, isbn from books
</select>
</statements>
</sqlMap>
Furthermore, much of the guesswork required to create the parameterizes queries used to pull information from the database and load a collection of Book objects has been added. Simply creating a new Linq DataContext object, passing the connection string to the database and calling the generic GetTable<T> (where T is class name. in this case Book) is all you need to get the results, versus creating the individual sql in the xml file and calling one of the QueryForObject or QueryForList methods found for IBatis.NET.
Last but not least, Linq provides the programmer with built-in sql like keywords used to build expressions that sort, aggregate and limit the original result set to some more specific or limited result result set without going back to the underlying database.
Although, this is a very simplicity view of mapping a database table to .NET class. This does give you a good picture to the additional overhead required to using IBatis.NET xml file mapping versus Microsoft's Linq to Sql attribute base mapping, and demonstrates how ORM is now built right into the .NET Framework. And, you be happy to know that your .NET 3.5 Linq to Sql applications will still run on .NET 2.0 because the new features are specific to the specific 3.5 .NET compiler.
Topics: Web/Tech
Hire us to design your site, build your application, serve billions of users and solve real problems.