What is Entity Framework Core?
Answer
Entity Framework Core (EF Core) is Microsoft's official ORM (Object-Relational Mapper) for .NET. It enables working with databases using .NET objects, eliminating most data-access boilerplate. Core concepts: DbContext: the main class coordinating EF Core functionality — represents a session with the database. DbSet<T>: represents a table. Migrations: code-based database schema versioning (dotnet ef migrations add, dotnet ef database update). LINQ queries: translated to SQL — context.Users.Where(u => u.Age > 18).ToListAsync(). Two approaches: Code First (define C# models → generate DB), Database First (scaffold models from existing DB). Supports: SQL Server, PostgreSQL, MySQL, SQLite, Cosmos DB. Key patterns: repository pattern, unit of work (built-in via DbContext.SaveChanges()). Avoid N+1 with eager loading: .Include(u => u.Orders).
Previous
What is dependency injection in ASP.NET Core?
Next
What is the difference between eager, lazy, and explicit loading in EF Core?
More C# / .NET Questions
View all →- Intermediate What is ASP.NET Core and how does it differ from ASP.NET Framework?
- Intermediate What is middleware in ASP.NET Core?
- Intermediate What is dependency injection in ASP.NET Core?
- Intermediate What is the difference between eager, lazy, and explicit loading in EF Core?
- Intermediate What is the Task Parallel Library (TPL) in C#?