Library Data v0.1.4

Generate or Scaffold ASP.NET Core Code

Generate or scaffold ASP.NET Core code — Razor Pages, Blazor components, MVC controllers, views, and Minimal API endpoints — without using ASP.NET Core CLI scaffolding/code-generation tools. Use when (1) adding CRUD pages, views, or API endpoints backed by Entity Framework (EF Core) and a database, (2) generating code to create, read, update, and delete data using a DbContext, (3) scaffolding UI components that match the project's existing CSS framework and coding patterns, or (4) creating data-driven forms, tables, and navigation for a model class. Do not use for non-ASP.NET projects or when CLI-based scaffolding is preferred.

Workflow

Step 1: Understand the Scaffolding Request

Parse the scaffolding request to identify:

  • Scaffolder type: Razor Pages, Blazor components, MVC controller, Minimal API, empty page/view/component
  • Model class and its namespace
  • DbContext: new or existing, database provider (SQLite, SQL Server, etc.)
  • Named items: controller name, endpoints class name, page name, view name, area name
  • Options: OpenAPI, async actions, partial view, custom layout
  • FK scope: whether to also scaffold CRUD for parent entities referenced by required foreign keys

Execution Checklists

Complete the applicable checklist in order. Do not stop after creating only the requested child resource when a required foreign key makes a parent resource necessary.

All EF scaffolders

  1. Inspect the project file, Program.cs, target model, validation attributes, navigation properties, and foreign keys before editing.
  2. Reuse the requested existing DbContext; otherwise create the requested context. Add only the required provider package and register it with AddDbContext using the requested provider and connection string. You will need to add Microsoft.EntityFrameworkCore.Design (PrivateAssets="all") when migrations are needed and it's missing.
  3. Generate complete CRUD for the requested entity and every required parent entity: list, details, create, edit, and delete.
  4. Use the EF migration lifecycle: create a migration and apply it. Never call EnsureCreated or seed the database in Program.cs.
  5. Restore, build, and test the generated project. Fix errors before reporting completion.

MVC, Razor Pages, and Blazor

  1. Inspect the existing layout, CSS, and representative UI before generating markup.
  2. Generate the complete child and required-parent UI flows, including a navigation path to each resource so users can create a parent before creating a child.
  3. Match the existing UI framework and conventions; preserve existing render-mode configuration for Blazor.

Minimal APIs

  1. Use a route group for each resource and map GET (list and by ID), POST, PUT, and DELETE endpoints for both child and required-parent resources.
  2. Add OpenAPI metadata to every endpoint: unique name, tags, description, success/error response metadata, and WithOpenApi when OpenAPI is enabled.
  3. Create an executable .http file with every CRUD request. Create parent records first, capture or clearly reuse their returned IDs in child requests, and run the requests in dependency order.

Step 2: Discover UI Style (non-API scaffolders only)

Skip this step for API controllers and Minimal API endpoints.

  1. Inspect the project's layout file (_Layout.cshtml, MainLayout.razor, or equivalent)
  2. Inspect the main CSS file (site.css, app.css, Tailwind config, etc.)
  3. Inspect 1–2 existing pages, views, or components in the project

All generated files MUST match the existing UI framework, CSS classes, and conventions. If Bootstrap is used, generate Bootstrap markup. If Tailwind is used, generate Tailwind markup.

Step 3: Apply Blazor-Specific Rules (Blazor scaffolders only)

Skip this step for non-Blazor scaffolders.

  • [SupplyParameterFromForm] properties MUST use = new() (not null!) — prevents EditForm crash on initial GET
  • Program.cs must chain .AddInteractiveServerComponents() on AddRazorComponents() and .AddInteractiveServerRenderMode() on MapRazorComponents<App>(). only add interactive server services/render mode when the generated components actually use @rendermode InteractiveServer (or the project already does).
  • Do not replace existing chained render mode calls (e.g., .AddInteractiveWebAssemblyRenderMode())

Step 4: Generate Code

Generate all code files manually. Follow these constraints:

  • DO NOT use any scaffolding CLI tools
  • DO NOT add packages beyond those required for the scaffolded functionality (e.g., do not add RuntimeCompilation, or other convenience packages)
  • Match the coding style of existing files in the project (naming conventions, indentation, namespace patterns)

#### Enrich API Endpoints with OpenAPI Metadata (API scaffolders only)

When generating Minimal API or MVC API endpoints with OpenAPI support enabled, add rich metadata to every endpoint so the OpenAPI document is descriptive and useful:

  • .WithName("GetTodoItems") — unique operation ID for each endpoint
  • .WithTags("TodoItems") — group endpoints by resource
  • .WithDescription("Returns all todo items") — human-readable summary
  • .Produces<List<TodoItem>>(StatusCodes.Status200OK) — document success response type
  • .Produces(StatusCodes.Status404NotFound) — document error responses
  • .ProducesValidationProblem() — for endpoints that validate input
  • .WithOpenApi() — opt the endpoint into OpenAPI generation (if not already globally enabled)

Example for a Minimal API GET endpoint:

group.MapGet("/", async (TodoDbContext db) =>
        await db.TodoItems.ToListAsync())
    .WithName("GetAllTodoItems")
    .WithTags("TodoItems")
    .WithDescription("Returns all todo items")
    .Produces<List<TodoItem>>(StatusCodes.Status200OK);

Step 5: Set Up Entity Framework (if applicable)

Skip this step if the scaffolding request does not involve Entity Framework.

  • DO NOT seed the database in Program.cs — always use migrations
  • For dotnet ef: prefer dotnet tool restore from a local tool manifest. Only install globally if no manifest exists
  • Inspect the model for navigation properties and foreign keys. Ensure CRUD endpoints/pages exist for referenced entities
  • For API scaffolders: the .http file MUST create parent entities before child entities. Use FK values consistent with creation order

Step 6: Generate .http File (API scaffolders only)

Skip this step for non-API scaffolders.

  1. Create a .http file named {ModelName}.http in the project directory. If a file with that name exists, append a numeric suffix (Product2.http, Product3.http) until unique
  2. Include sample requests for every CRUD endpoint scaffolded, including endpoints for parent/dependent entities
  3. Every request must target the correct URL path matching an actual mapped endpoint
  4. Request labels must accurately describe the action (e.g., "Create a category" must POST to the categories endpoint)
  5. Order requests by dependency: create parent entities before child entities
  6. When possible, capture IDs from parent creation responses using your HTTP client's variable/templating features and reuse them as foreign key values in child-entity POST payloads
  7. If your client cannot capture response values, add comments indicating which FK IDs must be updated after running the parent creation requests; do not leave unrealistic placeholder or assumed FK values that do not correspond to actual parent records when executing the requests

Step 7: Verify

  1. Run dotnet restore && dotnet build from the project directory
  2. If Entity Framework is used and this is the first verification:

- Run dotnet ef migrations add InitialCreate - Run dotnet ef database update - You will need to change "InitialCreate" to something else if you run this more than once, as EF Core requires unique migration names.

  1. If API scaffolder:

- Inspect Properties/launchSettings.json — if a profile named https exists, use dotnet run --launch-profile https - Execute EVERY .http request one at a time in dependency order - Report method, URL, and status code for each request - Stop and fix if any request returns non-2xx

  1. Fix all errors until a clean build succeeds

References

Related skills

Framework Data 2,138 tokens

Design, tune, or review EF Core data access with proper modeling, migrations, query translation, performance, and lifetime management for modern .NET applications.

Microsoft.EntityFrameworkCore.*

Use ManagedCode.MarkItDown when a .NET application needs deterministic document-to-Markdown conversion for ingestion, indexing, summarization, or content-processing workflows.

ManagedCode.MarkItDown
Library Data 549 tokens

Use ManagedCode.Storage when a .NET application needs a provider-agnostic storage abstraction with explicit configuration, container selection, upload and download flows, and…

ManagedCode.Storage.CoreManagedCode.Storage.AzureManagedCode.Storage.Aws+1