Entity Framework Core Documentation

Welcome to the official documentation for Entity Framework Core (EF Core). EF Core is a modern, object-relational mapper (ORM) for .NET that enables .NET developers to work with a database using .NET objects. It supports a variety of database providers, allowing you to choose the database that best suits your needs.

What is Entity Framework Core?

Entity Framework Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework ORM. It's designed to be more performant and offer more flexibility than its predecessors, while maintaining a familiar API for developers who have used EF in the past.

Key Features:

Getting Started

To begin using EF Core, you'll typically need to install the appropriate NuGet packages for your chosen database provider and the core EF Core libraries. The most common starting point is to define your domain model (your C# classes) and then use EF Core to create and manage your database schema.

Tip: For new projects, it's recommended to start with EF Core 7 or later.

Common Scenarios

EF Core is used in a wide range of applications, from simple CRUD (Create, Read, Update, Delete) operations to complex enterprise systems. Some common scenarios include:

Example: Basic CRUD Operation

Here's a simplified example demonstrating how to query and save data with EF Core:


using (var context = new BlogContext())
{
    // Create a new blog
    var blog = new Blog { Url = "http://sample.com" };
    context.Blogs.Add(blog);
    context.SaveChanges();

    // Read blogs
    var blogs = context.Blogs.ToList();

    // Update a blog
    var firstBlog = context.Blogs.First();
    firstBlog.Url = "http://updated-sample.com";
    context.SaveChanges();

    // Delete a blog
    var blogToDelete = context.Blogs.Single(b => b.BlogId == 1);
    context.Blogs.Remove(blogToDelete);
    context.SaveChanges();
}
            
Note: This is a basic example. Real-world applications often involve more complex configurations and error handling.

Further Reading

Explore the following sections to dive deeper into specific aspects of Entity Framework Core: