Simple Object Mapping Toolkit

A few days ago, I talked about an interesting topic when developing applications that require frequent access to databases (eg. SQL Server). Many frameworks are existing to connect your Business Layer to a Database : the best known is often Entity Framework.

After multiple projects using EF, we’ve decided to avoid this framework. Why? First for performance reasons and secondly to avoid maintenance problems (see my previous article about the migration of EF5 to EF6).

We prefer to use mapping tools where we need to create SQL queries and these tools convert data results to equivalents C# objects. For small projects, EF can be a solutions but when you need to develop a large application with a large database, you prefer manipulate, optimize queries to retrieve data quickly.

Dapper.NET is a toolkit, developed by the Stackoverflow team, to simplify querying and to convert SQL data to C# objects (see examples in my presentation).

But Dapper.NET will extend your IDbConnection interface (eg. SqlConnection). It’s easy to use, but to define guideline and for future evolution, I prefer to create an object with properties, methods and a live cycle. For these reasons, I’ve published the project SqlDatabaseCommand: you create an object SqlDatabaseCommand (eg. in a DataService), you define properties and you execute your command. Logging, Exceptions, Entities Generator are automatically managed by the toolkit.

using (var cmd = new SqlDatabaseCommand(CONNECTION_STRING))
    cmd.CommandText.AppendLine("SELECT * FROM EMP");
    var emps = cmd.ExecuteTable<Employee>();
Posted in General

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: