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 0000000000000000000000000000000000000000..e6d8979056d8981ce41e65178f2f981b9afd3633 --- /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 0000000000000000000000000000000000000000..62c631855e49581da9267f1bc2540174ccc2bebe --- /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 0000000000000000000000000000000000000000..26054c74f8207a52273b804ee3f4fd2904f84d60 --- /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 0000000000000000000000000000000000000000..72c83fb82f8492cedddc260fc285e47cf26d8c6d --- /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 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 0000000000000000000000000000000000000000..9a61413663e6354d3a08847fb1fae203bb9d7878 --- /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