Entity Framework
By Microsoft
NET that lets developers work with relational databases using strongly typed C# classes and LINQ queries instead of raw SQL.
Definition
Entity Framework (EF) is Microsoft's Object-Relational Mapping (ORM) framework for .NET that lets developers work with relational databases using strongly typed C# classes and LINQ queries instead of raw SQL.
Overview
Entity Framework maps .NET classes to database tables through a `DbContext`, which represents a session with the database and exposes `DbSet<T>` collections for each entity type. Developers can query data using LINQ — Language Integrated Query — writing expressions like `context.Users.Where(u => u.Age > 18)` that EF translates into SQL at runtime, giving compile-time checked, IntelliSense-friendly database access inside ASP.NET Core applications. The modern, cross-platform version, Entity Framework Core (EF Core), succeeded the original .NET Framework-only Entity Framework and supports PostgreSQL, MySQL, SQLite, and SQL Server through provider packages, alongside Microsoft's own Azure SQL Database. EF Core supports two primary modeling workflows: Code First, where C# classes drive the schema and migrations generate the corresponding DDL, and Database First, where an existing schema is scaffolded into C# classes. Schema evolution in EF Core is handled through its own migrations system — `dotnet ef migrations add` generates a C# migration file capturing the diff between the current model and the last snapshot, conceptually parallel to what Alembic does for SQLAlchemy or what Flyway does with SQL files, but expressed in C# and applied via `dotnet ef database update`. EF Core includes change tracking (so modified entities are detected automatically before `SaveChanges()`), lazy/eager loading of related entities, and a growing set of performance features like compiled queries and no-tracking queries for read-heavy scenarios, making it the default data-access layer for most greenfield .NET applications.
Key Features
- DbContext and DbSet<T> model the database session and entity collections
- LINQ-to-SQL query translation with compile-time type checking
- Code First and Database First modeling workflows
- C#-based migrations generated via dotnet ef migrations add
- Automatic change tracking before SaveChanges() commits updates
- Lazy, eager, and explicit loading strategies for related entities
- Cross-platform, multi-database support via EF Core provider packages
- Performance features including compiled queries and no-tracking reads
Use Cases
Frequently Asked Questions
From the Blog
What Is Named Entity Recognition in NLP
Named entity recognition finds and classifies names of people, places, organizations, and more in text. Learn how NER works and where it is used.
Read More AI & TechnologyGraphRAG vs Vector RAG: When Relationships Beat Similarity
Vector RAG retrieves passages that look like the question; GraphRAG retrieves entities and the edges between them. This article compares the two on multi-entity and aggregation questions, on build and maintenance cost, and gives a test for deciding which your corpus actually needs.
Read More Data ScienceHow to choose the right cross-validation splitter for your data
The splitter follows from the structure of your data, not from convention. Stratify when classes are imbalanced, group when rows share an entity, split by time when order carries information, and combine when several apply. A mismatched splitter gives an optimistic score no tuning can fix.
Read More