QuickDevGuide

Home › .NET Framework (Legacy & Enterprise)

Entity Framework 6 — .NET Framework (Legacy & Enterprise)

EF6 is the ORM of the .NET Framework era (EF Core is its modern successor, and EF6 also runs on modern .NET for migrations). Feature EF6 API Context class ShopContext : DbContext with DbSet<T> properties Mapping conventions, DataAnnotations, or Fluent API in OnModelCreating Querying LINQ to Entities, Include() for eager loading Read-only queries AsNoTracking() Saving Add, modify tracked entities, SaveChanges() (one transaction) Migrations Enable-Migrations, Add-Migration, Update-Database (Package Manager Console) Raw SQL Database.SqlQuery<T>(), ExecuteSqlCommand (parameterised) Performance tips Disable lazy loading for APIs (Configuration.LazyLoadingEnabled = false) to avoid N+1 queries, project to DTOs with Select, and keep contexts short-lived (one per request).

Key Takeaways