DbContext & DbSet Basics
Set up a DbContext, define entities, configure the connection string, and run your first query.
What Is Entity Framework Core?
EF Core is the official .NET Object-Relational Mapper (ORM). It maps C# classes (entities) to database tables and lets you query and save data using LINQ — no SQL required for most operations.
Defining an Entity
An entity is a plain C# class whose properties map to database columns. By convention, a property named Id or <TypeName>Id becomes the primary key.
public class Product
{
public int Id { get; set; }
public string Name { get; set; } = "";
public decimal Price { get; set; }
public int Stock { get; set; }
public DateTime CreatedAt { get; set; }
}