Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 41 ยท Getting Started

What Is Entity Framework Core?

Learn what Entity Framework Core is, what an ORM does, how EF Core compares with ADO.NET and Dapper, and how this course runs its examples honestly on the site.

Almost every real application stores data in a database, and almost every database speaks SQL, while your C# code speaks in classes, properties and collections. Entity Framework Core (EF Core) is the official object-relational mapper (ORM) for .NET. It sits between the two worlds: you work with C# objects and LINQ queries, and EF Core turns them into SQL, runs it, and turns the rows back into objects.

This first lesson explains what that means in practice, where EF Core fits next to hand-written ADO.NET and micro-ORMs like Dapper, and what you can and cannot run on this site. It is the base for the whole course: models, migrations, queries, relationships, saving, performance and testing.

The problem EF Core solves

Without an ORM, saving a product looks like this: open a connection, build a SQL string with parameters, execute it, read the result with a data reader, and copy each column into a property by hand. Every table needs the same boring code, and a typo in a column name only fails at run time.

With EF Core you describe your data as classes, ask for what you want with LINQ, and let the framework do the plumbing:

C#
// Real EF Core code (read-only on this site).
var cheap = await db.Products
    .Where(p => p.Price < 20m)
    .OrderBy(p => p.Name)
    .ToListAsync();

The compiler checks the property names, your IDE autocompletes them, and EF Core produces a parameterized SELECT ... WHERE Price < @p ORDER BY Name for you. Renaming Price in the class becomes a refactoring, not a search through strings.

What EF Core actually does

EF Core has a handful of jobs. Keep this list in mind, because each chapter of the course covers one or two of them.

  • Mapping: classes become tables, properties become columns, navigation properties become foreign keys. See DbContext and Models.
  • Querying: LINQ expression trees are translated to SQL for your database (Querying with LINQ).
  • Change tracking: EF Core remembers the objects it loaded and notices what you changed.
  • Saving: SaveChanges turns those changes into INSERT, UPDATE and DELETE statements inside a transaction.
  • Migrations: versioned scripts that evolve the schema along with the model (Migrations basics).

What EF Core does

Maps Classes to tables
Queries LINQ to SQL
Tracks Notices changes
Saves INSERT, UPDATE, DELETE

One API, many databases

1 / 3

EF Core, ADO.NET and Dapper

There is a spectrum of data-access tools in .NET, and none of them is "the best" in every situation.

Tool You write Strength Cost
ADO.NET SQL, readers, mapping Full control, fastest path Lots of boilerplate
Dapper SQL, mapping is automatic Very fast, simple No change tracking, no migrations
EF Core LINQ and entity classes Productivity, tracking, migrations Abstraction you must understand

Many teams use EF Core for everyday create/update work and drop to raw SQL or Dapper for a few hot reports. EF Core itself lets you run raw SQL when you need it (Translation and raw SQL), so the choice is rarely all or nothing. If you want to see the layer underneath, the ADO.NET lesson shows it.

Where EF Core fits in an application

EF Core is a library, not a server. You add a NuGet package for your database provider (SQL Server, PostgreSQL, SQLite and others), define a class that derives from DbContext, and register it in your app. In an ASP.NET Core web app the DbContext is created once per request through dependency injection; in a console app you create it yourself in a using block.

flowchart LR
    A["Controller / service"] --> B["DbContext"]
    B --> C["Provider (SQL Server, SQLite, ...)"]
    C --> D[("Database")]
    B -. "tracks entities" .-> E["Change tracker"]

The DbContext is the one object your code talks to.

What runs on this site

Be clear about this before you start: this site cannot run EF Core itself. The runner is a sandbox with the .NET 10 compiler and the base libraries, but no NuGet packages and no database. So the course works like this:

  • Real EF Core code appears in plain, read-only code blocks. Every command (dotnet ef migrations add) and every snippet is what you would type in your own project. Output is shown only where it is certain.
  • Runnable stand-ins appear in the interactive editors. They are small, honest C# programs that reproduce the idea behind a feature (a mini change tracker, an expression-tree-to-SQL translator) with in-memory data. They are labelled as stand-ins every time, and they are not EF Core.

To run the real thing you only need the .NET SDK and, for the first lessons, the SQLite provider, which stores the database in one file.

A first stand-in: objects and rows

The editor below is a stand-in. It keeps "rows" in dictionaries and converts them to and from a C# record, which is the core of what any ORM does.

C# Stand-in: objects to rows and back

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

An ORM does this generically with reflection and generated code, for every entity, in both directions.

A second stand-in: LINQ is data, not code

The key trick behind EF Core is that Where(p => p.Price < 20) on an IQueryable is not run as C#. It is captured as an expression tree that a provider can inspect. The stand-in below prints that tree.

C# Stand-in: an expression tree you can read

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The same lambda can be compiled and run as normal C# (Compile()), or inspected and translated. EF Core does the second.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does an ORM like EF Core mainly do?

    An ORM sits between your object model and the relational database, translating queries and changes both ways.
  2. 2. Which statement about EF Core is true?

    EF Core is a library. Providers (SQL Server, PostgreSQL, SQLite...) adapt it to a database, and raw SQL is supported when needed.
  3. 3. Why can EF Core translate a LINQ filter into SQL?

    On IQueryable, lambdas become Expression objects (data). A provider walks the tree and emits SQL.
  4. 4. How are the interactive editors in this course related to real EF Core?

    The runner has no NuGet and no database, so real EF Core code is read-only and the runnable parts are honest stand-ins.

Summary

  • EF Core is Microsoft's ORM: classes and LINQ in, SQL and objects out.
  • It maps, queries, tracks changes, saves and migrates.
  • ADO.NET gives control, Dapper gives speed, EF Core gives productivity; mixing them is normal.
  • LINQ over IQueryable works because lambdas become inspectable expression trees.
  • On this site real EF Core code is read-only and the runnable examples are labelled stand-ins.

Next: Your First EF Core App