Modeling, DbContext configuration, migrations
The Support Desk model
arrives: Customer, Agent, Category, Ticket and TicketComment, configured with the Fluent API
(required strings and lengths, a RowVersion concurrency token, the planned indexes, one OnDelete rule per
relationship and a CHECK constraint on the title), scaffolded into the InitialCreate migration through the
design-time factory, applied with MigrateAsync at start in Development, and filled by a development-only
seeder.
Run it
cd "LearnWisej-Samples/Data Binding with EF Core Course/Module 2/SupportDesk.Web"
dotnet run -f net10.0 --urls http://localhost:5402
In Development the host migrates and seeds SupportDesk.Web/App_Data/supportdesk.db before the first
session (five customers, three agents, six categories, sixty tickets, sixteen comments). Delete the file
(and its -wal / -shm companions) to start over. Tests: dotnet test SupportDesk.Tests.
Migration commands, from the Module 2 folder (--framework is needed because the web project multi-targets):
dotnet ef migrations list --project SupportDesk.Data --startup-project SupportDesk.Web --framework net10.0
dotnet ef migrations script --idempotent --project SupportDesk.Data --startup-project SupportDesk.Web \
--framework net10.0 --output artifacts/sql/supportdesk_migrations.sql
What to try
The page has countButton, btnSeed, statusLabel, a counts line (customers, agents, categories,
tickets, pending migrations) and the two failure paths lab step 8 asks for.
- Count tickets: 60 tickets in the Support Desk database.
- Seed development data (
btnSeed): the database is seeded at start, so it reports nothing to seed: 60 tickets already exist. On an empty database it seeds and the counts line updates. - Save a 200-character title: the CHECK constraint refuses the insert; a friendly
AlertBoxsays the database rejected the change, the counts do not move, and the exception goes to the console log. - Delete a customer with tickets:
DeleteBehavior.Restrictrefuses it; This customer still has tickets and cannot be deleted.