What is ORM?

Blog > ORM - Object Relational Mapping

What is ORM?

ORM stands for Object Relational Mapping. Simply, ORMs are used for converting from one data type to another between programming language and database. This enables developers to use different databases with different programming languages and vica versa, eliminates data parsing/conversion effords and possible errors along the way. Generally, they are used with relational databases along with the object-oriented programming aproach. In the context of database being MSSQL and programming language being C#, what an ORM does is that it maps database system type to POCOs (plain old CLR object or plain old class object)[1]. These two type systems[2] might not have the same set of logical rules to comprise a data, which means a conversion between them is necessary, and thats where the ORM comes in.

In the scenario where there are multiple and possibly interconnected relations between objects, CRUD[3] operations might get out of hand. Imagine a `Hospital´ object, having a couple of simple type[4] fields like name, and some relational object fields like `Departments´, then these departments having `Doctors´, `Rooms´, `Chief´, `Inventory´ objects, and each of these objects having simple type fields. These objects are represented as POCO in the programming language, might also be called Entity models or classes. CRUD operations of these objects could get very complex in terms of persistency, ACID properties of the database, structuring and optimizing queries, including reference (relational) objects only when needed along with concern of data integrity. This where the ORM comes into place, it blurs the line between the transition from Entity to database value types and vice versa, helping with the concerns over the CRUD operations, it simplifies things, helping developers to focus on other important things. ORMs also plays a big role with the code-first[5] approach helping more Domain-Driven designs[6] along with an agile development[7].



1. POCO: https://en.wikipedia.org/wiki/Plain_old_CLR_object

2. Type system: https://en.wikipedia.org/wiki/Type_system

3. CRUD: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete

4. Value types: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types#built-in-value-types

5. Code-first approach: https://www.entityframeworktutorial.net/code-first/what-is-code-first.aspx

6. Domain-Driven Design: https://martinfowler.com/bliki/DomainDrivenDesign.html

7. Agile software development: https://en.wikipedia.org/wiki/Agile_software_development