From 33730e40aabbf2718fe0fccbc7db949bc603c4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9B=A6?= <2196258247@qq.com> Date: Sun, 29 Dec 2024 19:31:28 +0800 Subject: [PATCH 1/4] =?UTF-8?q?20241223=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... -\345\255\246\347\224\237\350\241\250.md" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "\345\210\230\346\233\246/20241223 -\345\255\246\347\224\237\350\241\250.md" diff --git "a/\345\210\230\346\233\246/20241223 -\345\255\246\347\224\237\350\241\250.md" "b/\345\210\230\346\233\246/20241223 -\345\255\246\347\224\237\350\241\250.md" new file mode 100644 index 0000000..c2d7177 --- /dev/null +++ "b/\345\210\230\346\233\246/20241223 -\345\255\246\347\224\237\350\241\250.md" @@ -0,0 +1,39 @@ +## 使用迁移创建数据库 +1. dotnet add package Microsoft.EntityFrameworkCore.SqlServer +2. dotnet tool install --global dotnet-ef +3. dotnet add package Microsoft.EntityFrameworkCore.Design +4. dotnet ef migrations add InitialCreate +5. dotnet ef database update + +## 了解IEnumerable +``` + (可迭代,可遍历) + ----->IEnumerable<----- + | | + | | + ICollection IQueryable + (集合) (linq,可查询) + | + | + IList + (集合) +``` +## 出现405错误 +1. 参数类型出错 +2. method对不上 + +## 或许更美观? +在View中的cshtml中加 +```cshtml +@model Student; +

编辑-学生-@Model.StudentName

+``` + +## 对我来说,暂时没用,但是先写上吧 +```cshtml +@model IEnumerable; +``` + +```cs +ViewBag["Title"]="ABc"; +``` \ No newline at end of file -- Gitee From 2712b62cb745f25060db1377444746ba56eb6927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9B=A6?= <2196258247@qq.com> Date: Sun, 29 Dec 2024 19:33:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?20241225=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25 -\350\277\236\350\241\250\346\237\245\350\257\242.md" | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 "\345\210\230\346\233\246/20241225 -\350\277\236\350\241\250\346\237\245\350\257\242.md" diff --git "a/\345\210\230\346\233\246/20241225 -\350\277\236\350\241\250\346\237\245\350\257\242.md" "b/\345\210\230\346\233\246/20241225 -\350\277\236\350\241\250\346\237\245\350\257\242.md" new file mode 100644 index 0000000..deba231 --- /dev/null +++ "b/\345\210\230\346\233\246/20241225 -\350\277\236\350\241\250\346\237\245\350\257\242.md" @@ -0,0 +1,6 @@ +1. 查询功能 method=get +from表单中的name与传到控制台的string类型参数名字相同 +[FromQuery]==>查询字符串 + +前 || 后 前对后不执行 +判断条件1 | 判断条件2 1执行成功会继续执行2 \ No newline at end of file -- Gitee From 4fed82ccc611d9ebdb54378fa760fc2bead817c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9B=A6?= <2196258247@qq.com> Date: Sun, 29 Dec 2024 19:34:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?20241226=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20241226 -\346\210\220\347\273\251\350\241\250.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" diff --git "a/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" "b/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" new file mode 100644 index 0000000..e69de29 -- Gitee From 1b1e2a0ef6e5dbdb5476826627c87c27d8f06423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9B=A6?= <2196258247@qq.com> Date: Sun, 29 Dec 2024 19:35:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?20241226=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... -\346\210\220\347\273\251\350\241\250.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git "a/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" "b/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" index e69de29..1076e3c 100644 --- "a/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" +++ "b/\345\210\230\346\233\246/20241226 -\346\210\220\347\273\251\350\241\250.md" @@ -0,0 +1,29 @@ +### 成绩表linq查询 +```cs +public IActionResult Index(string keyword) + { + var list = _db.Scores.ToList(); + var stus = _db.Students.Where(x=>!x.IsDeleted).ToList(); + var cours = _db.Courses.Where(x=>!x.IsDeleted).ToList(); + var res = list.Select(x => { + var tmpStu = stus.FirstOrDefault(y=>y.Id==x.StudentId); + var tmpCourse = cours.FirstOrDefault(z=>z.Id==x.CourseId); + return new{ + x.Id, + x.StudentId, + StudentName = tmpStu == null ? "" : tmpStu.StudentName, + x.CourseId, + CourseName = tmpCourse == null ? "默认课程" : tmpCourse.CourseName, + x.Score + }; + }); + return View(res);s + // keyword = string.IsNullOrEmpty(keyword) ? " ": keyword.Trim(); + // if (string.IsNullOrEmpty(keyword)) + // { + // return View(_db.Scores.ToList()); + // } + // keyword = keyword.Trim(); + // var list = _db.Scores.Where( x => x.StudentId.ToString().Contains(keyword)).ToList(); + } +``` \ No newline at end of file -- Gitee