ASP.NET Core Web API (.NET 9) for managing video games. Data is persisted in SQL Server with Entity Framework Core (code-first migrations and seed data).
Learning guide: CONCEPTS.md — explanations of every C#, .NET, and EF Core concept used in this project, with a senior-developer revisit section and study checklist.
VideoGamemodel —Id,Title,Platform,Developer,Publisher- Entity Framework Core + SQL Server —
VideoGameDbContextregistered inProgram.cs - Code-first migrations — create/update the
VideoGameDbdatabase from the model - Seed data — sample games configured with
HasDatainOnModelCreating - CRUD endpoints — controller uses EF Core against the database (not an in-memory list)
- API docs — OpenAPI + Scalar in Development
.gitignore— standard ignores for .NET build/IDE artifacts
- .NET 9 SDK
- SQL Server Express (local instance:
localhost\SQLExpress) - EF Core tools (Package Manager Console in Visual Studio, or
dotnet ef)
Connection string in appsettings.json:
"ConnectionStrings": {
"DefaultConnection": "Server=localhost\\SQLExpress;Database=VideoGameDb;Trusted_Connection=true;TrustServerCertificate=true;"
}From Package Manager Console (default project: this API):
Add-Migration Initial
Update-Database
# After adding/changing HasData seed configuration:
Add-Migration SeedData
Update-DatabaseOr with the .NET CLI (requires dotnet-ef):
dotnet ef migrations add Initial
dotnet ef database updatesqlcmd -S localhost\SQLExpress -E -d VideoGameDb -Q "SELECT Id, Title, Platform FROM VideoGames"Or in SSMS: connect to localhost\SQLExpress → database VideoGameDb → table dbo.VideoGames → Select Top 1000 Rows.
dotnet run- HTTP:
http://localhost:5139 - HTTPS:
https://localhost:7018 - Scalar UI: https://localhost:7018/scalar/v1
Base path: /api/VideoGame
| Method | Endpoint | Description | Success |
|---|---|---|---|
GET |
/api/VideoGame |
Get all video games | 200 OK |
GET |
/api/VideoGame/{id} |
Get one video game by id | 200 OK |
POST |
/api/VideoGame |
Create a video game (Id from SQL identity) |
201 Created |
PUT |
/api/VideoGame/{id} |
Update an existing video game | 204 No Content |
DELETE |
/api/VideoGame/{id} |
Delete a video game | 204 No Content |
Missing ids return 404 Not Found. Changes are saved to SQL Server and persist across restarts.
POST /api/VideoGame
{
"title": "God of War Ragnarök",
"platform": "PS5",
"developer": "Santa Monica Studio",
"publisher": "Sony Interactive Entertainment"
}PUT /api/VideoGame/1
{
"title": "Spider-Man 2 Remastered",
"platform": "PS5",
"developer": "Insomniac Games",
"publisher": "Sony Interactive Entertainment"
}You can also try the requests in VideoGameApi.http.
VideoGameApi/
├── Controllers/
│ └── VideoGameController.cs # EF Core CRUD actions
├── Data/
│ └── VideoGameDbContext.cs # DbContext + HasData seeding
├── Migrations/ # EF migration files (keep in source control)
├── VideoGame.cs # Model
├── Program.cs # DI, DbContext, OpenAPI, Scalar
├── appsettings.json # SQL Server connection string
├── VideoGameApi.http # Sample HTTP requests
├── .gitignore
├── README.md
└── CONCEPTS.md # Study guide for concepts used in this project
- CRUD uses
VideoGameDbContextwith async EF Core APIs (ToListAsync,FindAsync,SaveChangesAsync). - Seed data lives in
VideoGameDbContext.OnModelCreatingviaHasData. Add a new migration after changing seeds, then runUpdate-Database. - Do not delete the
Migrationsfolder after generating migrations. - Scalar and OpenAPI are enabled only when
ASPNETCORE_ENVIRONMENTisDevelopment.