From 7882aa975b300d4ff0c2ef7ae30962b1f6c213ed Mon Sep 17 00:00:00 2001 From: Tkyoo <2951237202@qq.com> Date: Sun, 25 Jan 2026 13:12:48 +0000 Subject: [PATCH] zy Signed-off-by: Tkyoo <2951237202@qq.com> --- .../20260119.md" | 10 ++++++ .../20260121.md" | 20 ++++++++++++ .../20260122.md" | 31 +++++++++++++++++++ .../20260123.md" | 15 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 "\344\273\235\345\207\257\345\205\203/20260119.md" create mode 100644 "\344\273\235\345\207\257\345\205\203/20260121.md" create mode 100644 "\344\273\235\345\207\257\345\205\203/20260122.md" create mode 100644 "\344\273\235\345\207\257\345\205\203/20260123.md" diff --git "a/\344\273\235\345\207\257\345\205\203/20260119.md" "b/\344\273\235\345\207\257\345\205\203/20260119.md" new file mode 100644 index 0000000..b168da3 --- /dev/null +++ "b/\344\273\235\345\207\257\345\205\203/20260119.md" @@ -0,0 +1,10 @@ +什么是模型绑定? + +模型绑定是ASP.NET Core将HTTP请求数据自动映射到控制器动作参数的过程。 + +绑定来源: + +路由数据(Route data) +查询字符串(Query string) +表单数据(Form data) +JSON/XML请求体 \ No newline at end of file diff --git "a/\344\273\235\345\207\257\345\205\203/20260121.md" "b/\344\273\235\345\207\257\345\205\203/20260121.md" new file mode 100644 index 0000000..eb8a542 --- /dev/null +++ "b/\344\273\235\345\207\257\345\205\203/20260121.md" @@ -0,0 +1,20 @@ + +笔记 +EF Core的工作方式 + +Code First:先写代码(模型),再生成数据库(我们采用的方式) +Database First:已有数据库,根据数据库生成代码 +Model First:先设计模型图,再生成代码和数据库 +迁移(Migration) + +安装EF Core工具(如果尚未安装)dotnet tool install --global dotnet-ef + +创建迁移dotnet ef migrations add InitialCreate + +应用迁移到数据库dotnet ef database update + +删除最近一次迁移dotnet ef migrations remove + +生成SQL脚本(不执行)dotnet ef migrations script + +更新到特定迁移dotnet ef database update TargetMigration \ No newline at end of file diff --git "a/\344\273\235\345\207\257\345\205\203/20260122.md" "b/\344\273\235\345\207\257\345\205\203/20260122.md" new file mode 100644 index 0000000..969db73 --- /dev/null +++ "b/\344\273\235\345\207\257\345\205\203/20260122.md" @@ -0,0 +1,31 @@ +笔记 +步骤1:安装2个包 + +安装EF Core SQLite提供程序(Microsoft.EntityFrameworkCore.Sqlite) + +dotnet add package Microsoft.EntityFrameworkCore.Sqlite -v 8.0 +安装EF Core设计工具(用于迁移)(Microsoft.EntityFrameworkCore.Design) + +dotnet add package Microsoft.EntityFrameworkCore.Design -v 8.0 +步骤2:定义数据库上下文 + +定义数据库 + +public Dbset 名称{get;set} +配置数据库连接字符串 + +步骤3:执行数据库迁移 + +2个先决条件 + +不能眼编译错误 +项目没有在运行,不在运行状态 +命令 + +dotnet ef migrations add XXX +如果没有安装ef工具,使用如下命令 + +dotnet tool install --global dotnet-ef +步骤4:将迁移文件更新应用到数据库 + +dotnet er database update \ No newline at end of file diff --git "a/\344\273\235\345\207\257\345\205\203/20260123.md" "b/\344\273\235\345\207\257\345\205\203/20260123.md" new file mode 100644 index 0000000..9f4fcf5 --- /dev/null +++ "b/\344\273\235\345\207\257\345\205\203/20260123.md" @@ -0,0 +1,15 @@ +笔记 +查找功能 + +public IActionResult Index(string keyword) + { + // 直接使用数据库表中的数据 + IEnumerable list = db.Products; + + // 当keyword不为空时,在数据库表中查找关键内容 + if (!string.IsNullOrEmpty(keyword)) + { + list = list.Where(p => p.ProductName.Contains(keyword) || p.Tag.Contains(keyword)); + } + return View(list); + } \ No newline at end of file -- Gitee