Entity Framework Core (EF Core) is Microsoft's ORM for .NET—map C# classes to database tables, query with LINQ, and track changes. It supports SQL Server, PostgreSQL, SQLite, MySQL, and more via provider packages.
Why EF Core in ASP.NET
- Productive CRUD without hand-written SQL for every query
- Migrations version schema alongside code
- Integrates with DI as scoped
DbContext - Similar role to Django ORM or Java JPA/Hibernate
Registration in Program.cs
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
Important interview questions and answers
- Q: EF Core vs Dapper?
A: EF for model-centric apps and migrations; Dapper for hand-tuned SQL and micro-ORM performance. - Q: DbContext thread-safe?
A: No—use one instance per request (scoped lifetime).
Self-check
- What DI lifetime should DbContext use?
- Name one database provider besides SQL Server.
Interview prep
- EF Core vs Dapper?
EF Core suits model-centric apps with migrations and change tracking; Dapper is a micro-ORM for hand-tuned SQL when you need maximum control.