Dapper-dot-net aka Micro-ORM

a simple object mapper for .NET

After listening to Hanselminutes show #262 I became curious and have looked a bit at Dapper to check what it really is.

First of all, it’s implemented as a single file you can drop in your project. It’s created for and at stackoverflow. I heard somewhere that it should be 400 lines, but it looks more like 1200. It’s nice that I can understand much of how the ORM works just by browsing this file. But there are a few methods with a lot of il.Emit, which I can just hope works fine.

Dapper works as an extension of the IDbConnection interface through extension methods. With the use of generics it can return typed objects otherwise it returns dynamic objects.

I thought that perhaps a simple ORM like this is only targeted to a single provider, but of course it uses ADO.NET, so all providers supported there should work with Dapper. But as I understand it, you write raw SQL, so it doesn’t help you if you want to switch provider. But how often do you really do that? And it also means that you don’t have to learn a new language.

The goal has been to create a really fast and simple mapper, and according to their benchmarks, they have succeeded to make it fast. I think I heard that stackoverflow first used Linq2sql and Dapper is 4 times faster than Linq2SQL and 13 times faster than Entity Framework for a SELECT statement with 500 rows to Poco’s in their test case.

Of course it has some limitations, for example it lacks a identity map, but I suppose it makes it a good fit when you use a CQRS architecture and separate commands and queries?

I like the simplicity, and the speed, so I might try it for real some day.

This Post Has 3 Comments

  1. David Boarman

    I tested Dapper and retrieved 160k records of 40 fields into a strongly typed collection in an average of 6.5 sec. For many data-centric applications, it is the retrieval that is often the bottleneck. I understand that there are some extension methods for mapping and other CRUD operations. I have yet to work with those.

  2. Itzik Saban

    before i begin i just want to say that i only heard about dapper few days ago and never used it.

    it seems to me that it can be called “micro ORM” only because that currently it doesn’t support many required features. for example: it only supports the R but not the CUD.
    When it will try to support this, it will probably have no choice but to deal with associations and id mappings.
    It will have to know who is a parent and who is a child before doing CUD.
    It will have to deal with concurrency.
    What about polymorphism? and so forth.

    I believe it will eventually grow until it no longer can be called “micro”.
    Still, that doesn’t mean this is not a blessed initiative – at the end, it might be an improvement for exiting tools of ORM e.g. NHibernate.

Leave a Reply