Entity Framework Core
Official .NET ORM from Microsoft — maps C# classes to database tables with LINQ query support, automatic migrations, and change tracking. EF Core features: DbContext with DbSet<T> properties for each entity, LINQ queries (dbContext.Agents.Where(a => a.Active).OrderBy(a => a.Name).ToListAsync()), Code First migrations (dotnet ef migrations add), relationships (HasMany/HasOne/HasForeignKey), value objects, owned entities, raw SQL (FromSqlRaw), and global query filters. Supports SQL Server, PostgreSQL (Npgsql), SQLite, MySQL, Oracle, and Cosmos DB. DbContext pooling for high-throughput scenarios. Interceptors for query logging and modification. The standard ORM for .NET agent services.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
EF Core LINQ queries are parameterized by default preventing SQL injection. NEVER use FromSqlRaw with string concatenation — use parameters or FromSqlInterpolated. Store connection strings in Azure Key Vault or AWS Secrets Manager for production agent services. Enable global query filters for multi-tenant agent data isolation.
⚡ Reliability
Best When
You're building a .NET agent service that needs ORM, migrations, and LINQ queries against a relational database — EF Core is the standard .NET data access layer with the richest ecosystem.
Avoid When
You need maximum performance for bulk operations (use Dapper), your team prefers stored procedures, or you're using NoSQL databases.
Use Cases
- • Agent data persistence with EF Core — class AgentDbContext : DbContext { public DbSet<Agent> Agents { get; set; } }; var agents = await context.Agents.Where(a => a.UserId == userId).ToListAsync() in agent service repository
- • EF Core migrations for agent schema — dotnet ef migrations add AddAgentCapabilities; dotnet ef database update deploys agent schema changes; migration history tracked in __EFMigrationsHistory table for rollback tracking
- • Agent relationship modeling — Agent.HasMany(a => a.Tools).WithOne(t => t.Agent).HasForeignKey(t => t.AgentId) defines agent-tool relationship; Include(a => a.Tools) eager loads agent tools in single query
- • EF Core global query filters for multi-tenant agents — modelBuilder.Entity<Agent>().HasQueryFilter(a => a.TenantId == currentTenantId) automatically scopes all agent queries to current tenant; prevents cross-tenant data access
- • Agent audit trail with EF Core interceptors — SaveChangesInterceptor logs all entity state changes (Added/Modified/Deleted) to audit table; automatic agent change tracking without manual audit code in every repository
Not For
- • High-performance bulk operations — EF Core loads entities into memory for change tracking; bulk inserts/updates of thousands of agent records are slow; use EF Core BulkExtensions or raw SQL for agent bulk operations
- • NoSQL databases — EF Core's Cosmos DB provider is limited; for agent services on MongoDB, use MongoDB .NET driver or EF Core MongoDB provider (preview); relational EF Core patterns don't translate well to document stores
- • Stored procedure-heavy databases — EF Core can call stored procedures but isn't designed around them; for agent services with complex SP-based data access, Dapper provides cleaner stored procedure integration
Interface
Authentication
EF Core connects via connection string with database credentials. Use Azure Managed Identity or AWS IAM auth for production agent databases via Microsoft.EntityFrameworkCore.SqlServer connection string options.
Pricing
EF Core is MIT licensed, maintained by Microsoft. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ DbContext is not thread-safe — injecting DbContext as singleton causes concurrent request data corruption; always register DbContext with AddDbContext (scoped lifetime); each agent HTTP request gets own DbContext instance; sharing across threads causes InvalidOperationException in concurrent agent services
- ⚠ N+1 queries without Include — loading agents then accessing agent.Tools in loop triggers per-agent SQL query; use .Include(a => a.Tools) or .ThenInclude() for eager loading; EF Core does not warn about N+1 by default; enable sensitive logging and query logging to detect agent N+1 patterns
- ⚠ AsNoTracking() is critical for read-heavy agent queries — tracked entities consume memory proportional to result set; agent list endpoints loading thousands of records without AsNoTracking() cause memory pressure; all read-only agent queries should use .AsNoTracking() or .AsNoTrackingWithIdentityResolution()
- ⚠ Migrations must be applied before deployment completes — EF Core migrations don't auto-apply on startup by default; agent deployments without Database.MigrateAsync() call or separate migration step leave database behind code; run migrations as part of deployment pipeline, not on every app start (causes startup race condition in multi-instance agent services)
- ⚠ Lazy loading requires virtual navigation properties AND proxy package — lazy loading (accessing agent.Tools without Include) requires Microsoft.EntityFrameworkCore.Proxies + UseLazyLoadingProxies() + virtual keyword on navigation properties; missing any element causes silent eager-not-loaded behavior (null collection) not exception; use explicit loading or eager loading for predictable agent data access
- ⚠ String queries bypass LINQ type safety — FromSqlRaw('SELECT * FROM Agents WHERE Id = ' + id) is SQL injection vulnerability; always use FromSqlRaw with parameters: FromSqlRaw('SELECT * FROM Agents WHERE Id = {0}', agentId) or FromSqlInterpolated for agent raw SQL queries; never concatenate user input into EF Core raw SQL
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Entity Framework Core.
Scores are editorial opinions as of 2026-03-06.