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 0000000000000000000000000000000000000000..c2d7177162f82c9b9f82c3da46eeb62677c7ea55 --- /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 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 0000000000000000000000000000000000000000..deba231488804f4fa994cb0a2bb2f65abcabbf1a --- /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 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 0000000000000000000000000000000000000000..1076e3cf11e97a94c344aa6953e43f21d18d043f --- /dev/null +++ "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