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:
- Database Providers: Supports SQL Server, SQLite, PostgreSQL, MySQL, Oracle, and more through community providers.
- LINQ Queries: Write database queries using Language Integrated Query (LINQ), which translates them into efficient SQL.
- Change Tracking: Automatically tracks changes made to entities.
- Migrations: Manages database schema changes over time, allowing for seamless evolution of your database.
- Asynchronous Operations: Supports asynchronous programming patterns for improved application responsiveness.
- Dependency Injection: Integrates seamlessly with .NET's built-in dependency injection system.
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.
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:
- Building web applications with ASP.NET Core.
- Developing desktop applications with WPF or WinForms.
- Creating data access layers for microservices.
- Migrating existing applications to use modern data access patterns.
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();
}
Further Reading
Explore the following sections to dive deeper into specific aspects of Entity Framework Core: