Interview: Micro ORM, Entity Framework, Stored Proc

vishal gupta
2 min readOct 28, 2020

Object-Relational Mapping (ORM) is a technique that lets you query and manipulates data from a database using an object-oriented paradigm. It returns you the relational objects instead of (in terms of c# that you are using) ADO.NET objects.

ORM and Micro ORM (EF and Dapper)

Entity Framework is an open-source ORM library for .NET applications.

Entity Framework has many good features like generating queries for you to make your application database independently, cache your data for future calls, manage unit of work.

Tracking is one of the responsibilities of UoW. When the object is requested (SQL query) for the first time, it causes a round trip to the database. This object is then saved in-memory cache. Full ORM keeps track of changes done to this already loaded object(s). If the same object is requested again then EF returns the object from memory cache instead calling to the database. This way, considerable time is saved.

Note: Dapper does not support this feature.

But, this benefit is only applicable if the same object(s) loaded multiple times. Also, if the number of objects loaded in memory is too high, this will slow down your application as then the time required to check the objects in memory will be higher.

Dapper is a micro ORM or it is a simple object mapper framework which helps to map the native query output to a domain class or a C# class. It is built by the StackOverflow team.

But if you really want to improve your application performance then Dapper owns the title of King of Micro ORM in terms of performance.

Myth: “Stored procedures are precompiled and cached so the performance is much better.” It is not valid any more.

From 2005 onwards, all SQL statements, irrespective of it’s a SQL coming from inline code or stored procedure or from anywhere else, they are compiled and cached.

At the end of the day I will still prefer stored procedures. The choice of choosing stored procedures will not be performance but it will be more from the aspect of maintenance ease.

--

--