Entity Framework Core (EF Core) is a cross-platform .NET library for database access. It is an object-relational mapper (ORM): it maps entity classes to tables, properties to columns, and objects to rows. You work with .NET objects while EF Core handles much of the connection, SQL generation, and result mapping. section 12.1.1 section 12.6 section 12.1.2
Start by choosing a database provider, such as SQLite, PostgreSQL, or SQL Server. Install its NuGet package and the EF Core design package, then define entity classes and a DbContext. Register the DbContext with ASP.NET Core dependency injection using a provider and connection string. EF Core builds its model from the entities and DbSet properties; its conventions provide a starting point that you can customize. section 12.2 section 12.2.1 section 12.6
A typical path from model to stored data is:
- Create and apply a migration after defining or changing entities. Migrations record schema changes so an existing database can be updated rather than replaced. section 12.3
- Use a LINQ query to describe data to retrieve; EF Core generates SQL and maps the results to objects. section 12.1.2
- Keep database operations in a service layer rather than putting them directly in minimal API endpoint handlers. section 12.2
Updating an existing entity
In a recipe API, the service loads a recipe by ID with DbSet.FindAsync, checks that it exists, changes its properties, and calls DbContext.SaveChangesAsync. EF Core tracks changes and generates the database update. FindAsync can return an already-tracked entity without another database call. section 12.4.4 section 12.1.2
The abstraction saves work, but it does not remove the need to understand database behavior. Hidden query patterns can produce an N+1 problem, and applying migrations can cause data loss. Before production, consider column sizes, validation, concurrent updates, transient failures, and whether synchronous or asynchronous calls suit the application. EF Core is distinct from Entity Framework 6.x; moving between them is not a simple upgrade. section 12.1.2 section 12.3 section 12.5 section 12.1.3



