Entity Framework Core

Welcome to Entity Framework Core

Entity Framework Core (EF Core) is a modern object‑relational mapper (ORM) for .NET. It enables .NET developers to work with a database using .NET objects, eliminating most of the data‑access code that developers usually need to write.

Key Features

  • Cross‑platform: runs on Windows, macOS, and Linux.
  • Supports LINQ queries, change tracking, updates, and schema migrations.
  • Works with many relational databases (SQL Server, SQLite, PostgreSQL, MySQL, etc.) and some NoSQL providers.

Sample Code

using Microsoft.EntityFrameworkCore;

public class BloggingContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlite("Data Source=blogging.db");
}

public class Blog
{
    public int BlogId { get; set; }
    public string? Url { get; set; }
    public List<Post> Posts { get; } = new();
}

public class Post
{
    public int PostId { get; set; }
    public string? Title { get; set; }
    public string? Content { get; set; }
    public int BlogId { get; set; }
    public Blog? Blog { get; set; }
}

Next Steps

Explore the sections in the left navigation to dive deeper into EF Core:

  • Getting Started – Set up your first EF Core project.
  • Modeling Data – Define entity classes and relationships.
  • Queries – Write LINQ queries and execute them.
  • Migrations – Evolve your database schema.
  • Performance – Optimize EF Core for large workloads.
  • Testing – Strategies for unit testing data access.