Tutorials ASP.NET Core Complete Tutorial (ShopNest)

EF Core CRUD Operations — Create, Read, Update, Delete

Learn EF Core CRUD Operations — Create, Read, Update, Delete in our free ASP.NET Core Complete Tutorial (ShopNest) series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
EF Core CRUD Operations — Create, Read, Update, Delete — ShopNest
Article 15 of 75 · Module 2: Entity Framework Core · ShopNest Product Management
Target keyword: ef core crud · Read time: ~29 min · .NET: 8 / 9 · Project: ShopNest Product Management

Introduction

ShopNest Product Management needs full CRUD — always use async methods in production (SaveChangesAsync, ToListAsync) to keep threads free under load.

After this article you will

  • Create with AddAsync; read with FindAsync and LINQ
  • Update tracked entities; implement soft delete
  • Build ProductsController with five views
  • Handle concurrency and errors in CRUD

Prerequisites

Concept deep-dive

// CREATE
await _db.Products.AddAsync(product);
await _db.SaveChangesAsync();

// READ
var product = await _db.Products.FindAsync(id);
var list = await _db.Products.Where(p => !p.IsDeleted).ToListAsync();

// UPDATE — entity tracked from query
product.Price = dto.Price;
await _db.SaveChangesAsync();

// SOFT DELETE
product.IsDeleted = true;
product.DeletedAt = DateTime.UtcNow;
await _db.SaveChangesAsync();

AsNoTracking() for read-only lists — better performance, no accidental updates.

Hands-on — ShopNest Product Management

  1. Product entity with IsDeleted flag.
  2. ProductsController: Index, Details, Create, Edit, Delete (soft).
  3. Try/catch DbUpdateException on duplicate SKU.

Common errors & best practices

  • Sync SaveChanges on high traffic — blocks threads.
  • Update detached entity — attach or use Update() carefully.

Interview questions

Q: Find vs FirstOrDefault?
A: Find uses PK cache first; FirstOrDefault runs query with any predicate.

Summary

  • Always async CRUD in production ShopNest apps
  • Soft delete preserves audit history
  • AsNoTracking for read-only queries

Previous: EF Core Code First
Next: EF Core LINQ Queries

FAQ

When hard delete?

GDPR erasure or truly ephemeral data — otherwise prefer soft delete for e-commerce.

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ASP.NET Core Complete Tutorial (ShopNest)
Course syllabus
Module 1: Foundations
Module 2: Entity Framework Core
Module 3: Dependency Injection & Middleware
Module 4: Authentication & Security
Module 5: Web API
Module 6: Advanced Architecture
Module 7: Testing
Module 8: Deployment & DevOps
Module 9: Real-World Projects
Module 10: Advanced Topics
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details