From ba8f7b96624b645c7e5a26a4a9592fc20e24bc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B7=E5=AD=90?= <3127903295@qq.com> Date: Sun, 7 Jun 2026 19:00:24 +0800 Subject: [PATCH 1/2] 1 --- ...50\256\260-\345\256\211\350\243\205SDK.md" | 10 +++++++++ ...33\345\273\272\351\241\271\347\233\256.md" | 21 +++++++++++++++++++ ...\254\224\350\256\260-nuget\345\214\205.md" | 15 +++++++++++++ "20260605\347\254\224\350\256\260-CRUD.md" | 21 +++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 "20260601\347\254\224\350\256\260-\345\256\211\350\243\205SDK.md" create mode 100644 "20260603\347\254\224\350\256\260-\345\210\233\345\273\272\351\241\271\347\233\256.md" create mode 100644 "20260604\347\254\224\350\256\260-nuget\345\214\205.md" create mode 100644 "20260605\347\254\224\350\256\260-CRUD.md" diff --git "a/20260601\347\254\224\350\256\260-\345\256\211\350\243\205SDK.md" "b/20260601\347\254\224\350\256\260-\345\256\211\350\243\205SDK.md" new file mode 100644 index 0000000..e6d8979 --- /dev/null +++ "b/20260601\347\254\224\350\256\260-\345\256\211\350\243\205SDK.md" @@ -0,0 +1,10 @@ +## 笔记 + +安装SDK + +1.访问 https://dotnet.microsoft.com/download/dotnet/8.0 +2.下载 .NET 8.0 SDK(不要下错成 Runtime) +3.双击安装包,按提示完成 + + +## 练习 \ No newline at end of file diff --git "a/20260603\347\254\224\350\256\260-\345\210\233\345\273\272\351\241\271\347\233\256.md" "b/20260603\347\254\224\350\256\260-\345\210\233\345\273\272\351\241\271\347\233\256.md" new file mode 100644 index 0000000..62c6318 --- /dev/null +++ "b/20260603\347\254\224\350\256\260-\345\210\233\345\273\272\351\241\271\347\233\256.md" @@ -0,0 +1,21 @@ +## 笔记 + +创建项目 + +在终端(PowerShell / bash)里: + + 切到你想放代码的目录:mkdir MyShopApi && cd MyShopApi + + 创建 Web API 项目:dotnet new webapi -n MyShopApi --use-controllers + + 进入项目目录:cd MyShopApi + + + webapi:项目模板名 + + -n MyShopApi:项目名(生成的目录名、命名空间) + + --use-controllers:用 Controller-based 风格(vs Minimal API) + + +## 练习 \ No newline at end of file diff --git "a/20260604\347\254\224\350\256\260-nuget\345\214\205.md" "b/20260604\347\254\224\350\256\260-nuget\345\214\205.md" new file mode 100644 index 0000000..26054c7 --- /dev/null +++ "b/20260604\347\254\224\350\256\260-nuget\345\214\205.md" @@ -0,0 +1,15 @@ +## 笔记 + +装 NuGet 包与 dotnet-ef 工具 + +安装NuGet 包 + + dotnet add package Microsoft.EntityFrameworkCore.Sqlite -v 8—— SQLite 数据库 provider + dotnet add package Microsoft.EntityFrameworkCore.Design-v 8—— 迁移命令依赖(dotnet ef) + +安装dotnet-ef 工具 + + dotnet tool install --global dotnet-ef + 验证:dotnet ef --version + +## 练习 \ No newline at end of file diff --git "a/20260605\347\254\224\350\256\260-CRUD.md" "b/20260605\347\254\224\350\256\260-CRUD.md" new file mode 100644 index 0000000..72c83fb --- /dev/null +++ "b/20260605\347\254\224\350\256\260-CRUD.md" @@ -0,0 +1,21 @@ +## 笔记 + + +CRUD改造 + +通过构造函数注入拿到AppDbContext实例: + + public class CategoriesController : ControllerBase + { + private readonly AppDbContext _db; + + public CategoriesController(AppDbContext db) + { + _db = db; + } + + // ... + } + + +## 练习 \ No newline at end of file -- Gitee From 1d118e81d8c0868b6a24bf69dc384694f1fbab08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B7=E5=AD=90?= <3127903295@qq.com> Date: Sun, 14 Jun 2026 21:09:43 +0800 Subject: [PATCH 2/2] 1 --- ...74\350\210\252\345\261\236\346\200\247.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "20260608\347\254\224\350\256\260-\345\257\274\350\210\252\345\261\236\346\200\247.md" diff --git "a/20260608\347\254\224\350\256\260-\345\257\274\350\210\252\345\261\236\346\200\247.md" "b/20260608\347\254\224\350\256\260-\345\257\274\350\210\252\345\261\236\346\200\247.md" new file mode 100644 index 0000000..9a61413 --- /dev/null +++ "b/20260608\347\254\224\350\256\260-\345\257\274\350\210\252\345\261\236\346\200\247.md" @@ -0,0 +1,29 @@ +## 笔记 + +一、核心概念 +一对多:主实体(一) → 子实体(多),通过外键关联,导航属性用来在实体间互相查询。 +例:班级(一) ↔ 学生(多) + +二、实体定义(EF Core) +- 1. 主实体(一) +```csharp +public class Class +{ + public int Id { get; set; } + public string Name { get; set; } + public List Students { get; set; } +} +``` + +- 2. 子实体(多) +```csharp +public class Student +{ + public int Id { get; set; } + public string StuName { get; set; } + public int ClassId { get; set; } + public Class Class { get; set; } +} +``` + +## 练习 \ No newline at end of file -- Gitee