What is EF Core?

The ORM that lets you query SQL with C#. No SQL scripts. 4 mins.

Your First "Aha" Moment: You already wrote SQL. EF Core just lets you write it in C#.

1. The Problem EF Core Solves

Without ORM:

var cmd = new SqlCommand("SELECT * FROM Users WHERE Age > @age", conn);
cmd.Parameters.AddWithValue("@age", 18);
var reader = cmd.ExecuteReader(); // 10 lines to map to List

With EF Core:

var users = await _db.Users.Where(u => u.Age > 18).ToListAsync();

Same SQL runs on database. But you wrote C#. IntelliSense, compile-time check, no string SQL.

โŒ ADO.NET/Dapper

You write SQL. You map results.
Rename column = app crashes at runtime.

โœ… EF Core

You write LINQ. EF maps it.
Rename property = compile error. Safe.

2. 3 Core Pieces You Must Know

EF Core ConceptReal World Meaning
DbContextYour database session. Unit of Work. Tracks all changes.
DbSet<User>Your table. Query it with LINQ.
SaveChanges()Commits all INSERT/UPDATE/DELETE in 1 batch.

3. Code First in 60 Seconds

Step 1: Install

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

Step 2: Model

public class User {
    public int Id { get; set; }
    public string Name { get; set; }
}

Step 3: DbContext

public class AppDbContext : DbContext {
    public DbSet Users { get; set; }
    public AppDbContext(DbContextOptions opt) : base(opt) { }
}

Step 4: Migration = Creates Table

Add-Migration Init
Update-Database
Stop Here. Think. EF Core didn't remove SQL. It just moved it. You still need to know SQL to debug slow queries.
Next lesson: DbContext lifetime. Get it wrong = memory leak + โ‚น50k Azure bill.
Career-Killer Mistake: Using EF Core for reports with 20 joins.
EF Core LINQ โ†’ SQL is 95% good. For complex GroupBy + Window Functions, write raw SQL or use Dapper. Right tool for right job.

Quick Check ๐Ÿง 

Ready for DbContext? You know WHAT EF Core is. Next: DbContext & DbSet teaches you DI lifetime, OnModelCreating, and the bug that crashes prod at 3 AM. Let's go โ†’

Comments on EF Core Intro (0)

No comments yet. Be the first to share your thoughts!