Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)5.8k · #14571

create-datadriven-aspnetcore

Skill này làm gì

Skill này viết code ASP.NET Core để tạo, đọc, cập nhật và xóa dữ liệu cho một mô hình, gồm trang, view, component và endpoint API. Skill dành cho lập trình viên .NET cần màn hình dữ liệu và API có cơ sở dữ liệu.

Khi nào nên dùng

  • ✓Khi bạn muốn có các trang tạo, sửa, liệt kê và xóa cho một mô hình trong dự án ASP.NET Core.
  • ✓Khi bạn muốn các endpoint API cho một mô hình dùng Entity Framework.
  • ✓Khi bạn muốn Razor Pages, view MVC hoặc component Blazor được tạo phù hợp với dự án.

Liên kết skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-data/skills/create-datadriven-aspnetcore/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/dotnet/skills/blob/main/plugins/dotnet-data/skills/create-datadriven-aspnetcore/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm các trang CRUD cho mô hình Product trong dự án ASP.NET Core của tôi, dùng layout và CSS hiện có.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent đọc layout, framework CSS và data context của dự án, viết các trang hoặc endpoint khớp với code hiện có, rồi dùng các lệnh dotnet chuẩn để build và chạy migration.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Generate or Scaffold ASP.NET Core Code

Generate ASP.NET Core scaffolded code — controllers, views, Razor Pages, Blazor components, Minimal API endpoints. The generated code matches the project's existing CSS framework, layout conventions, and coding patterns. No CLI-based scaffolding/code-generation tools are used; standard dotnet CLI commands for build, restore, and migrations are still expected.

When to Use

  • Adding CRUD pages, views, or components for a model in an ASP.NET Core project
  • Scaffolding API controllers or Minimal API endpoints with Entity Framework Core
  • Generating Razor Pages, MVC views, or Blazor components backed by a DbContext

When Not to Use

  • The project is not an ASP.NET Core project
  • You need to scaffold non-web artifacts (class libraries, console apps, etc.)

Inputs

Input Required Description
Scaffolding request Yes Natural-language description of what to scaffold (see format below)
Project file path Yes Full path to the target .csproj file
Solution root path Recommended Path to the solution root for multi-project solutions

Scaffolding Request Format

The scaffolding request should be a natural-language description of what to scaffold. The request must include the target project path and enough detail for the agent to generate the correct code. Examples:

Razor Pages with EF:

Scaffold Razor Pages with CRUD for the `<ModelName>` model (from `<Namespace>`) in project `<path-to-csproj>`.
Create a new DbContext `<DbContextName>` using <database-provider>.
Also scaffold CRUD for any entity that `<ModelName>` depends on via required foreign keys, so parent entities can be created first.

Blazor CRUD components:

Scaffold Blazor CRUD components for the `<ModelName>` model (from `<Namespace>`) in project `<path-to-csproj>`.
Create a new DbContext `<DbContextName>` using <database-provider>.

Minimal API endpoints:

Scaffold Minimal API endpoints for the `<ModelName>` model (from `<Namespace>`) in project `<path-to-csproj>`.
Name the endpoints class `<EndpointsClassName>`.
Create a new DbContext `<DbContextName>` using <database-provider>.
Enable OpenAPI support.

MVC Controller with views:

Scaffold an MVC controller with views and Entity Framework for the `<ModelName>` model (from `<Namespace>`) in project `<path-to-csproj>`.
Name the controller `<ControllerName>`.
Use existing DbContext `<DbContextName>`.
Generate views.

Empty items (no EF):

Scaffold an empty Razor Page named `<PageName>` in project `<path-to-csproj>`.

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 user
Câu hỏi thường gặp

Skill có dùng lệnh scaffold không?

Không. Skill viết code trực tiếp thay vì dùng công cụ scaffold của ASP.NET Core.

Skill có khớp với phong cách dự án của tôi không?

Có. Skill khớp với framework CSS, layout và mẫu code hiện có.

Skill có cần cơ sở dữ liệu không?

Có. Code được tạo dựa trên Entity Framework và một database context.

Chi tiết

Mô tả gốc của tác giả

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

repo: dotnet/skills

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14571
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự