LibraryService API persists data through two EF Core entities —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/marchena96/Paradigma-lab1/llms.txt
Use this file to discover all available pages before exploring further.
Library and Book — both defined in LibraryContext.cs and mapped to PostgreSQL tables (Libraries and Books) on Supabase. There is no Fluent API configuration; column types and constraints come entirely from the InitialCreate migration.
Library entity
C# class
Table schema — Libraries
| Column | Type | Constraints |
|---|---|---|
Id | integer | PK, Identity (auto-increment) |
Name | text | NOT NULL |
Location | text | NOT NULL |
Example JSON
Book entity
C# class
Table schema — Books
| Column | Type | Constraints |
|---|---|---|
Id | integer | PK, Identity (auto-increment) |
Name | text | NOT NULL |
Category | text | NOT NULL |
LibraryId | integer | FK → Libraries.Id, ON DELETE CASCADE |
IX_Books_LibraryId is created on LibraryId to speed up the per-library book queries issued by BooksService.
Example JSON
Relationship
OneLibrary has many Book records. The FK column LibraryId on the Books table references Libraries.Id with ON DELETE CASCADE, meaning that deleting a library automatically and atomically deletes all of its books at the PostgreSQL level — no application-level cleanup is required. This relationship is declared in the InitialCreate migration:
LibraryContext
LibraryContext is the single EF Core DbContext for the application. It exposes the two entity sets and accepts its options through constructor injection:
LibraryContext is registered in Startup.ConfigureServices as a DbContext pool (not a plain scoped service) to minimise the overhead of context creation under load:
- Pool size 20 — up to 20 context instances are kept alive and reused across requests.
- Npgsql retry-on-failure — transient connection errors trigger up to 1 automatic retry with a 5-second maximum delay.
Migrations
EF Core migrations provide a versioned history of every schema change. The sole migration in this project is20260528004745_InitialCreate, which creates both tables and the cascade FK in a single Up() operation.
Migrations are applied automatically at startup via db.Database.Migrate() inside Startup.Configure:
Migrate() when the active provider is SQLite (used by the xUnit integration-test project, which manages its schema with EnsureCreated instead). This prevents conflicts when both host processes — the real API and the test WebApplicationFactory — share the same Startup class.
The
BookForm DTO (used as the POST request body for api/libraries/{libraryId}/books) omits libraryId from the body. The library is always taken from the route parameter {libraryId} and assigned to Book.LibraryId by the controller, preventing the client from assigning a book to an arbitrary library. Category is optional in the DTO (string?) and defaults to string.Empty when absent, satisfying the PostgreSQL NOT NULL constraint.