Tutorials ASP.NET Core Complete Tutorial (ShopNest)

Database First Approach with EF Core (Scaffold)

Learn Database First Approach with EF Core (Scaffold) in our free ASP.NET Core Complete Tutorial (ShopNest) series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
Database First Approach with EF Core (Scaffold) — ShopNest
Article 21 of 75 · Module 2: Entity Framework Core · ShopNest Legacy HR System Migration
Target keyword: ef core database first · Read time: ~28 min · .NET: 8 / 9 · Project: ShopNest Legacy HR System Migration

Introduction

Not every ShopNest integration starts greenfield. Database First scaffolds entities from an existing HR database — common when migrating legacy systems at TCS/Wipro-style maintenance projects.

After this article you will

  • Run dotnet ef dbcontext scaffold with options
  • Extend scaffolded models with partial classes
  • Refresh after DBA schema changes
  • Map stored procedures and database views
  • Mix Code First for new modules on same DB

Prerequisites

Concept deep-dive

dotnet ef dbcontext scaffold   "Server=.;Database=LegacyHR;Trusted_Connection=True;"   Microsoft.EntityFrameworkCore.SqlServer   --output-dir Models/Scaffolded   --context-dir Data   --context LegacyHrContext   --force   --no-onconfiguring

Partial classes: never edit scaffolded files — add Employee.Partial.cs with computed properties.

// Keyless entity for DB view
modelBuilder.Entity<EmployeeSummaryView>(b =>
{
    b.HasNoKey();
    b.ToView("vw_EmployeeSummary");
});

// Stored procedure
var results = await _db.EmployeeBonuses
    .FromSqlRaw("EXEC hr.GetBonuses @Year = {0}", 2025)
    .ToListAsync();

Hands-on — ShopNest Legacy HR System Migration

  1. Scaffold from sample LegacyHR database (or LocalDB script).
  2. Partial class adds FullName computed property.
  3. Map reporting view as keyless entity for read-only dashboard.
  4. Document re-scaffold workflow for team when DBA adds columns.

Common errors & best practices

  • Editing generated files — overwritten on re-scaffold; use partials.
  • Scaffolding entire server with 200 tables — scaffold specific tables with --table flags.

Interview questions

Q: When Database First?
A: Legacy DB, no ownership of schema, brownfield migration.

Q: Code First vs Database First?
A: Code First — dev owns schema. Database First — DBA owns schema, app adapts.

Summary

  • Scaffold-DbContext reverse-engineers existing SQL Server
  • Partial classes extend without losing regeneration
  • Views and sprocs map to keyless entities / FromSqlRaw
  • Common in legacy HR migration scenarios

Previous: EF Core Performance Optimization
Next: EF Core with SQL Server — Advanced Features

FAQ

Can I mix Code First migrations with scaffolded context?

Use separate contexts or carefully merge — one DbContext per bounded context is cleaner.

How update after schema change?

Re-scaffold with --force or add migration if you own schema via Code First.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain CLR & types in the context of ASP.NET Core Complete Tutorial (ShopNest).
Short answer: The CLR loads assemblies, manages memory (GC), and JIT-compiles IL to native code. Value types live on the stack or inline in objects; reference types live on the heap with GC tracking. Real-world example (…
Mid Detailed
What are common mistakes teams make with ASP.NET Core when using ASP.NET Core Complete Tutorial (ShopNest)?
Short answer: ASP.NET Core is cross-platform, uses Kestrel, middleware pipeline, and built-in DI. Requests flow: routing → middleware → endpoints → filters → action. Real-world example (ShopNest) In a ShopNest .NET servi…
Senior Detailed
How would you debug a production issue related to EF Core in a ASP.NET Core Complete Tutorial (ShopNest) application?
Short answer: EF Core maps C# entities to tables, tracks changes, and translates LINQ to SQL. Migrations version schema; Include/ThenInclude load graphs. Real-world example (ShopNest) In a ShopNest .NET service, explain…
Junior Detailed
Describe a real-world scenario where Testing mattered in a ASP.NET Core Complete Tutorial (ShopNest) project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Testing i…
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