5. Entity Framework Core
ASP.NET Core Entity Framework Core - Complete Guide
Practical Guide + Technical Reference
📋 Table of Contents
Part 1: Practical Guide (Hands-On)
Part 2: Technical Reference (Deep Dive)
PART 1: PRACTICAL GUIDE
1. EF Core Basics
What is an ORM?
Code-First vs Database-First
Approach
When to Use
Starting Point
When to Use EF Core
EF Core Evolution Timeline
2. 3 Ways to Set Up EF Core
Method 1: SQL Server (Most Common) 🎯 RECOMMENDED
Method 2: SQLite (Development & Learning) 📚 GREAT FOR LEARNING
Method 3: In-Memory Database (Testing) 🧪
Database Provider Comparison
Provider
NuGet Package
Connection String Example
Best For
3. DbContext Essentials
Basic DbContext Structure
DbSet Properties
OnConfiguring vs OnModelCreating
Method
Purpose
When to Use
3 Ways to Configure DbContext
Complete DbContext Example
4. Defining Models (Entity Classes)
Simple Entity
Primary Key Conventions
Data Annotations
Annotation
Purpose
Navigation Properties
Complete Model Examples
5. CRUD Operations
Create (C)
Read (R)
Update (U)
Delete (D)
6. Migrations
Migration Workflow
3 Methods to Create Migrations
Creating Migrations Step-by-Step
Applying Migrations
Rolling Back Migrations
Seed Data
Production Migrations Best Practices
7. Relationships
One-to-Many Relationship
One-to-One Relationship
Many-to-Many Relationship ✨ EF Core 5.0+
Relationship Delete Behaviors
Behavior
What Happens
8. Querying Patterns
AsNoTracking (Read-Only Queries)
Projection (Select)
Filtering (Where)
Sorting (OrderBy)
Pagination (Skip/Take)
GroupBy
Complete Querying Example
9. Troubleshooting Common Issues
Issue 1: No Database Provider Configured
Issue 2: Entity Not Tracked
Issue 3: N+1 Query Problem
Issue 4: Lazy Loading Not Working
Issue 5: Migrations Not Applying
Issue 6: Connection String Not Found
Issue 7: Tracking Multiple Instances
10. Best Practices
✅ DO
❌ DON'T
Performance Tips
PART 2: TECHNICAL REFERENCE
11. Important Interfaces & Classes Reference
DbContext Class ⭐⭐⭐
Member
Type
Description
DbSet Class ⭐⭐⭐
Member
Return Type
Description
Method
Description
ModelBuilder Class ⭐⭐
Method
Purpose
ChangeTracker Class
Member
Description
EntityEntry Class
Property
Description
Entity States
State
Description
When
12. Configuration Deep-Dive
OnModelCreating Patterns
Fluent API Complete Reference
Global Query Filters
Value Conversions ✨ EF Core 2.1+
Owned Entities ✨ EF Core 2.0+
Table Splitting
13. Advanced Topics
Raw SQL Queries
Stored Procedures
Concurrency Handling
Shadow Properties
Interceptors ✨ EF Core 3.0+
DbContext Pooling ✨ EF Core 2.0+
14. Performance Optimization
Query Performance Tips
Batch Operations ✨ EF Core 7.0+
Connection Resiliency
Monitoring and Logging
Summary
Last updated