Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 5, 2026·3 min de lecture

EF Core — Modern Object-Database Mapper for .NET

Entity Framework Core is the official ORM for .NET, supporting LINQ queries, change tracking, migrations, and multiple database backends including SQL Server, PostgreSQL, SQLite, and Cosmos DB.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
EF Core Overview
Commande d'installation directe
npx -y tokrepo@latest install d62ba569-78af-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Entity Framework Core (EF Core) is the official object-relational mapper for .NET applications. It allows developers to work with databases using C# objects and LINQ queries instead of raw SQL. EF Core supports code-first and database-first workflows with automatic schema migrations.

What EF Core Does

  • Maps C# classes to database tables and translates LINQ queries into efficient SQL at runtime
  • Tracks changes to entity objects in memory and generates optimized INSERT, UPDATE, and DELETE statements on save
  • Provides a migrations system that versions database schemas alongside application code
  • Supports multiple database providers including SQL Server, PostgreSQL, MySQL, SQLite, and Azure Cosmos DB
  • Implements lazy loading, eager loading, and explicit loading patterns for related data navigation

Architecture Overview

EF Core follows a provider model where a core library handles change tracking, query translation, and the Unit of Work pattern, while database-specific providers implement SQL generation and connection management. The DbContext class serves as the primary entry point, managing entity lifecycle and database sessions. Query translation uses an expression tree visitor that walks LINQ expressions and compiles them into provider-specific SQL. Migrations are generated as C# code files that can be applied forward or rolled back.

Self-Hosting & Configuration

  • Install via NuGet packages: the core library plus a database provider package for your target database
  • Configure the DbContext with a connection string in Program.cs or appsettings.json
  • Use the dotnet ef CLI tool or Package Manager Console for migration management
  • Supports dependency injection natively with ASP.NET Core's service container
  • Connection pooling and retry policies are configurable per provider for production deployments

Key Features

  • LINQ-to-SQL translation that generates parameterized queries to prevent SQL injection
  • Automatic change tracking with snapshot-based or proxy-based detection strategies
  • Global query filters for implementing soft deletes and multi-tenancy at the model level
  • Raw SQL escape hatches for complex queries that LINQ cannot express efficiently
  • Compiled queries for frequently executed LINQ expressions to reduce translation overhead

Comparison with Similar Tools

  • Dapper — Micro-ORM that maps SQL results to objects without change tracking; EF Core provides full ORM features at the cost of more abstraction
  • NHibernate — Mature .NET ORM with XML-based mappings; EF Core uses fluent API and conventions with tighter .NET integration
  • LINQ to DB — Lightweight LINQ provider focused on SQL generation; EF Core adds migrations, change tracking, and identity management
  • Prisma — TypeScript ORM with schema-first design; EF Core is code-first with C# type safety
  • SQLAlchemy — Python ORM with similar Unit of Work pattern; EF Core integrates more deeply with .NET dependency injection

FAQ

Q: Which databases does EF Core support? A: SQL Server, PostgreSQL (via Npgsql), MySQL (via Pomelo), SQLite, Azure Cosmos DB, and several community-maintained providers for Oracle, Firebird, and others.

Q: Can EF Core handle high-performance scenarios? A: Yes. Features like compiled queries, no-tracking queries, bulk operations (EF Core 7+), and connection resilience make it suitable for production workloads. For extreme throughput, combine with Dapper for hot paths.

Q: How do migrations work in team environments? A: Migrations are generated as C# files that get committed to source control. The team applies them sequentially, and EF Core tracks which migrations have been applied via a history table.

Q: Does EF Core support stored procedures? A: Yes. You can call stored procedures using raw SQL methods and map the results to entity types or anonymous objects.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires