juniorEntity Framework
How do you perform basic CRUD operations in EF Core?
Updated Apr 28, 2026
Short answer
CRUD is handled by DbSet methods: Add() for Create, LINQ for Read, modifying objects for Update, and Remove() for Delete.
Deep explanation
- Create: Add an entity to the DbSet. 2. Read: Use LINQ (e.g., FirstOrDefault) to fetch data. 3. Update: Modify a tracked entity; EF Core detects the change. 4. Delete: Pass the entity to the Remove method. Finally, call SaveChangesAsync() to execute the SQL.
Real-world example
A REST API controller that supports POST, GET, PUT, and DELETE endpoints for managing products.
Common mistakes
- Forgetting to call SaveChanges() after modifying entities, resulting in no database updates.
Follow-up questions
- Does Find() hit the database immediately?