diff --git "a/\351\231\206\346\273\242\351\222\260/20241216.md" "b/\351\231\206\346\273\242\351\222\260/20241216.md" new file mode 100644 index 0000000000000000000000000000000000000000..dce84f1b4360ce2198112bc9959b14a9e3b92da1 --- /dev/null +++ "b/\351\231\206\346\273\242\351\222\260/20241216.md" @@ -0,0 +1,9 @@ +1. Select:选择或投影元素。 +2. Where:过滤元素。 +3. OrderBy / OrderByDescending:对结果进行排序。 +4. GroupBy:对元素进行分组。 +5. Join:执行联合操作,类似于SQL中的JOIN。 +6. Aggregate:执行聚合操作,如求和、平均值等。 +7. Any / All:检查集合中是否存在/全部元素满足条件。 +8. Count:返回集合中的元素数量。 +9. FirstOrDefault / LastOrDefault:返回集合中的第一个/最后一个元素,如果集合为空,则返回默认值。 \ No newline at end of file diff --git "a/\351\231\206\346\273\242\351\222\260/20241218.md" "b/\351\231\206\346\273\242\351\222\260/20241218.md" new file mode 100644 index 0000000000000000000000000000000000000000..c7b163a1ed79185f56561efdebcb0cce3554ddc2 --- /dev/null +++ "b/\351\231\206\346\273\242\351\222\260/20241218.md" @@ -0,0 +1,9 @@ +## 1. 生成迁移文件 dotnet ef migrations add XXX + +1. 前提: + - 得安装依赖包,命令:dotnet add package Microsoft.EntityFrameworkCore.Design + - 需要一个工具,ef工具,安装命令:dotnet tool install --global dotnet-ef + - 要求程序不能编译错误,如果想确认有没有编译错误,请使用命令:dotnet build + - 程序不能处于运行状态 + +## 2. 将迁移文件同步到数据库 \ No newline at end of file diff --git "a/\351\231\206\346\273\242\351\222\260/20241219.md" "b/\351\231\206\346\273\242\351\222\260/20241219.md" new file mode 100644 index 0000000000000000000000000000000000000000..86f4639b480cd0030fa25d300a455bcd0daf49de --- /dev/null +++ "b/\351\231\206\346\273\242\351\222\260/20241219.md" @@ -0,0 +1,73 @@ +``` +using Microsoft.AspNetCore.Mvc; +using ScoreManager.Models; + +namespace ScoreManager.Controllers; + +public class CoursesController : Controller +{ + private readonly ScoreDbContext _db; + public CoursesController() + { + _db = new ScoreDbContext(); + } + public IActionResult Index(string keyword) + { + keyword = string.IsNullOrEmpty(keyword) ? "" : keyword.Trim(); + if (string.IsNullOrEmpty(keyword)) + { + var list = _db.Courses.ToList(); + return View(list); + } + var res = _db.Courses.Where(x => x.CourseName.Contains(keyword)).ToList(); + return View(res); + + } + public IActionResult Edit(int id) + { + var obj = _db.Courses.FirstOrDefault(x => x.Id == id); + return View(obj); + } + + [HttpPost] + public IActionResult Edit(Course input) + { + var obj = _db.Courses.FirstOrDefault(x => x.Id == input.Id); + if (obj == null) + { + return NotFound(); + } + obj.CourseName = input.CourseName; + _db.SaveChanges(); + return RedirectToAction("Index"); + } + public IActionResult Delete(int id) + { + var obj = _db.Courses.FirstOrDefault(x => x.Id == id); + return View(obj); + } + public IActionResult DeleteConfirm(int id) + { + var obj = _db.Courses.FirstOrDefault(x => x.Id == id); + if (obj == null) + { + return NotFound(); + } + _db.Courses.Remove(obj); + _db.SaveChanges(); + return RedirectToAction("Index"); + } + public IActionResult Create() + { + return View(); + } + + [HttpPost] + public IActionResult Create(Course input) + { + _db.Courses.Add(input); + _db.SaveChanges(); + return RedirectToAction("Index"); + } +} +``` \ No newline at end of file