Dapper Micro ORM

Posted on July 19, 2020 • eddrichjanzzen

The .NET ecosystem has always been a widely used platform for developing handsdown awesome applications! With the .NET stack alone there is a wide spectrum of projects that can be developed ranging from APIs (via ASP .NET), mobile apps, (via Xamarin), and even Windows Applications, (via WPF). With a history of being Windows specific, .NET has evolved over the years to allow open source. This revolutionary change gave rise to its increased in popularity as a development platform.

Dapper

Most modern .NET Web applications make use of Entity Framework as their ORM tool. An ORM or Object Relational Mapping is a development pattern that hides or encapsulates the data source by mapping the data into objects. There may advantages to adopting this type of pattern. For one, it enables developers to work with using objects rather than focusing on underlying database tables and columns where the data is stored. Not only does this provide greater benefits to how developers write their code, it also elimates the need for most of the boiler plate data acesss code that developers usually write. read more

In today's article we will be talking about a less conventional implementation of an ORM. We will be talking about the Dapper Micro ORM.

What is Dapper?

In simple terms, Dapper is a object mapper for .NET. It owns the title fo "King of Micro ORM". It is virtually as fast as using a raw ADO.NET data reader. It allows one to be very flexible with writing SQL queries themselves thereby ensuring optimal performance. read more

Unlike the full-blown ORMs (ei, NHibernate, EntityFramework, or SQLAlchemy), Dapper focuses more on mapping the data to its code representation, leaving the other configurations upto the developer. This allows for some flexibility in the way the data is queried/manipulated. This increased flexibility however, comes with some benefits and drawbacks. Lets go over some of them.

The Advantages

  1. Faster Performance.
  • Being able to map the data directly to its code representation means less time spent on other tasks. Since micro-ORMS allow for configuration of the SQL scripts, it is possible to write more SQL optimized scripts instead of relying on the autogenerated SQL scripts by the regular ORMs. This thereby increases speed and performance.
  1. Lighter Weight.
  • Sometimes setting up a full blown ORM might be too much. Especially for smaller projects that only use a few entities, a lot of the functionalities provided by the regular ORMs are not needed.

The Disadvantages

  1. Database Migrations.
  • Regular ORMs usually come with a built in migration tool. Dapper on the otherhand does not. There is a need for one to set up a migration tools especially for larger projects. However, there are ways around this such as using DbUp, or Schema Compare available in Visual Studio.
  1. Working with Validation.
  • Micro ORMs focus more on mapping the data and fast performance at the expense of features such as validation. For apps that rely heaviliy on validation, it would be recommended to stick to using regular ORMs.

When should I consider using a micro-ORM?

It depends. It helps to carefully assess the requirments and to do proper research before making any decisions.

If you're developing a small utility application where performance of critical importance, perhaps using a micro ORM would come to be a good move. 😎

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel