A step-by-step build of an employee management app with ASP.NET Core MVC and EF Core 8, going from an annotated model and DbContext through Code First migrations and a scoped DAL to Razor views that create, read, update and delete records.
Key points
- Database access needs three NuGet packages: EntityFrameworkCore.SqlServer, .Tools and .Design, all kept on the same 8.0.x version.
- The `Employee` model carries `[Required]`, `[EmailAddress]`, `[StringLength]` and `[Range]`; `Id` becomes the primary key by convention.
- `ApplicationDbContext` maps the table with `ToTable("Employee")` and sets `Salary` to DECIMAL(18,2) via `HasPrecision(18, 2)`.
- `AddDbContext` registers the context as scoped, one instance per HTTP request, with `UseSqlServer` as the provider.
- `Add-Migration InitialCreate` and `Update-Database` in the Package Manager Console create the table and the `__EFMigrationsHistory` record.
- A scoped `EmployeeDAL` wraps `Add`, `Find`, `Remove` and `SaveChanges`, so the controller never talks to the DbContext directly.
Why it matters
This is aimed at developers meeting EF Core for the first time, and as that it holds up: the package trio, the Code First migration flow and the scoped registration are the parts people usually get wrong. Experienced readers learn nothing new, but some habits deserve a second look — synchronous `SaveChanges()` everywhere, no `AsNoTracking()` on the list query, and a DAL that only forwards calls to the context.
The connection string disables certificate trust, which the article itself flags as local-development only. Concurrency, paging and async APIs are not covered, so the pattern needs more work before it serves a real list screen.
This summary was generated by the agent from the original post on C# Corner. The full text and all rights belong to its author and publisher. Go to original