# What is an ORM?

An ORM (object-relational mapper) moves data between C# objects and database tables. Dapper is a micro-ORM, where you write the SQL and it fills the objects. Entity Framework Core is a full ORM, where you write LINQ and it writes the SQL, and also tracks and saves your changes.

Journeyman · C# · Entity Framework Core · Updated November 15, 2026

By Gregor Dzierzon

## After this lesson you can

- Explain what an ORM does, and how Entity Framework Core differs from Dapper

## Key takeaways

- An ORM moves data between C# objects and database tables.
- Dapper is a micro-ORM: you write the SQL, and it fills the objects.
- EF Core is a full ORM: you write LINQ, and it writes the SQL, so the filtering and sorting still happen in the database.
- EF Core also tracks and saves your changes and follows relationships, at the cost of some control, more to learn and a little speed.

Your C# code thinks in **objects**: a `Category` with a `CategoryName` property. SQL Server thinks in **tables**: a `Categories` row with a `CategoryName` column. Every app that uses a database has to move data back and forth between the two shapes.

You've done that three ways so far:

| Way | You write | Who fills the objects |
|---|---|---|
| ADO.NET | The SQL, plus a loop reading each column from a `SqlDataReader` | You |
| Dapper | The SQL | Dapper, by matching column names to properties |
| Entity Framework Core | No SQL: LINQ | Entity Framework Core, which also writes the SQL |

A library that maps between objects and tables is called an **ORM**, an *object-relational mapper*. Dapper is a small one, often called a **micro-ORM**. **Entity Framework Core** (EF Core) is Microsoft's full one.

## The same query, two ORMs

The products under $10, with Dapper:

```csharp
using SqlConnection connection = new SqlConnection(connectionString);
List<Product> cheap = (await connection.QueryAsync<Product>(
    "SELECT ProductId, ProductName, UnitPrice FROM Products WHERE UnitPrice < @MaxPrice ORDER BY ProductName;",
    new { MaxPrice = 10m })).ToList();
```

And with EF Core:

```csharp
List<Product> cheap = await db.Products
    .Where(p => p.UnitPrice < 10m)
    .OrderBy(p => p.ProductName)
    .ToListAsync();
```

The EF Core version is LINQ, exactly as in *LINQ and Lambdas*, but `db.Products` isn't a list in memory: it stands for the `Products` **table**. EF Core translates the whole chain into one SQL query, sends it to SQL Server, and fills a `Product` for each row that comes back:

```sql
SELECT [p].[ProductId], [p].[CategoryId], [p].[Discontinued], [p].[ProductName], [p].[UnitPrice], [p].[UnitsInStock]
FROM [Products] AS [p]
WHERE [p].[UnitPrice] < 10.0
ORDER BY [p].[ProductName]
```

The filtering and sorting happen in the database, as they should, not in your program.

## What a full ORM adds

Writing SQL for you is only the start. EF Core also:

- **tracks changes.** Load a product, change its price, call `SaveChanges()`, and EF Core works out and runs the `UPDATE` itself.
- **follows relationships.** A `Category` object can have a `Products` list, filled by a join EF Core writes.
- **can create and change the database** from your classes, with *migrations*. (This course uses existing databases, so you won't need them yet.)

## What it costs

- **Less control.** The SQL is EF Core's, not yours. It's usually good, but when a query is slow, you have to read SQL you didn't write.
- **More to learn.** Tracking, relationships, configuration: a full ORM has a lot of behavior to understand.
- **A little slower.** All that work takes time, though for most apps the difference is small.

The last lesson in this topic compares the two properly. First, the next two lessons show EF Core at work.

## Do it: list the products running low, in LINQ

With EF Core, you ask for Northwind's products in LINQ, and EF Core writes the SQL. That LINQ is the same as the LINQ you'd write over a list in memory, so practice it on one.

The method gets two values:

- `products`: the products, a `List<Product>`. Each `Product` has a `ProductName` and `UnitsInStock` (an `int`).
- `fewerThan`: the stock level that counts as low, an `int`, such as `10`.

For example, these five products, with `fewerThan` set to `10`:

| ProductName | UnitsInStock | Fewer than 10? |
|---|---|---|
| Chai | 39 | no |
| Northwoods Cranberry Sauce | 6 | yes |
| Konbu | 24 | no |
| Gorgonzola Telino | 0 | yes |
| Alice Mutton | 0 | yes |

The three that are low, sorted by name: Alice Mutton, Gorgonzola Telino, Northwoods Cranberry Sauce.

So `LowStock(products, 10)` returns a list of those three names, in that order.

**Your job:** write the method `LowStock(List<Product> products, int fewerThan)` so it returns the names of the products running low, a `List<string>`.

- Keep the products whose `UnitsInStock` is less than `fewerThan`.
- Sort them by `ProductName`, A to Z.
- Return their names.
- When no product is low, return an empty list.

Practiced live on the lesson page: write the C# right there and check it.

## Check yourself

1 question to try on the lesson page.

## So what

An ORM moves data between objects and tables so you don't have to. Dapper does the moving and leaves the SQL to you; EF Core writes the SQL too, from the LINQ you already know.

## Key terms

- ORM
- Micro-ORM
- Entity Framework Core

## Cheat sheets

- [What is an ORM?](https://www.ask-codey.com/cheat-sheets/entity-framework-core-what-is-an-orm-cheat-sheet)

Source: https://www.ask-codey.com/lessons/entity-framework-core-what-is-an-orm
