---
description: >-
  I aim to explain what an ORM does, as well as the pros and cons of using them
  in your projects.
---

# ORM(Object Relational Mapping)

## What is an ORM?

Object-relational-mapping is the idea of being able to write queries , as well as much more complicated ones, using the object-oriented paradigm of your preferred programming language.

![](https://697379079-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MNrO0PWI5eVuZV2v0d3%2F-MNrZL5ZHIWFb4c3u9Ap%2F-MNrcbkm9J7lcbleXYeI%2Fmain-qimg-fd2a83826f1c4ad025fd60060b865506.png?alt=media\&token=ee8d2595-e489-4279-b407-3bc2418decf2)

```
Select * from users where email = 'test@test.com';
///This is a Sql code.


var orm = require('generic-orm-library');
var user=orm("users").where({email:'test@test.com'});

//In these rows,we ve used an imaginary ORM library to
execute the exact same query,except we can write it in C#.

```

## What are some pros of using ORM?

\*It abstracts away the database system so that switching from MySQL to PosttgreSQL or whatever flavor you prefer,is easy..

\*Depending on the ORM you get a lot of advanced features out of the box,such as support for transactions,connection pooling,seeds,streams and all sorts of other goodies.

\*Many of the queriest you write will perform better than if you wrote them yourself.



## What are some cons of using ORM?

\*As a developer, it is important to understand what is happening under the hood. Since ORMs can serve as a crutch to avoid understanding databases and SQL, it can make you a weaker developer in that portion of the stack.

## Instance : 2;

```
we have  books class and 
we want to get which writer name is "Orhan Pamuk" ;
List books= new List(); 
sql = "SELECT * FROM LibraryWHERE Writer= 'Orhan Pamuk'";
 data = query(sql); // I over simplify ... 
while (row = data.next())
 { 
books k = new Kitap(); 
k.Writer=row["Writer"];
 books.add(kitap);
 }
```

After ORM Library it can be seen like  this ;

```
List Books= db.Books.Where(x=>x.Writer=="Orhan Pamuk").ToList();
```



references:blog.bitsrc.io/MarioHoyos,\
&#x20;                  emrebostan.com/orm



