Lesson 7 of 8Article18 min
Entity Framework Core Basics
Entity Framework Core maps C# classes to database tables, so you can query data with LINQ instead of writing raw SQL for every operation.
ORM basics with EF Core
Entity Framework Core maps C# classes to database tables, so you can query data with LINQ instead of writing raw SQL for every operation.
DbContext and model setup
Simple EF Core model
public class AppDbContext : DbContext
{
public DbSet<Student> Students => Set<Student>();
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) {}
}
public class Student
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Score { get; set; }
}Query with LINQ
var toppers = await db.Students
.Where(s => s.Score > 90)
.OrderByDescending(s => s.Score)
.ToListAsync();