From 92689fab47b914901ba859c3498d3101f4100deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=80=9D?= <1662679300@qq.com> Date: Sun, 29 Dec 2024 19:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9Aand=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20241223-\347\254\224\350\256\260.md" | 11 +++++++ ...34\347\264\242\344\275\234\344\270\232.md" | 23 +++++++++++++++ .../20241226-\347\254\224\350\256\260.md" | 29 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 "\346\235\216\346\200\235/20241223-\347\254\224\350\256\260.md" create mode 100644 "\346\235\216\346\200\235/20241225-\346\220\234\347\264\242\344\275\234\344\270\232.md" create mode 100644 "\346\235\216\346\200\235/20241226-\347\254\224\350\256\260.md" diff --git "a/\346\235\216\346\200\235/20241223-\347\254\224\350\256\260.md" "b/\346\235\216\346\200\235/20241223-\347\254\224\350\256\260.md" new file mode 100644 index 0000000..6ec4ce0 --- /dev/null +++ "b/\346\235\216\346\200\235/20241223-\347\254\224\350\256\260.md" @@ -0,0 +1,11 @@ +使用迁移创建数据库 + +dotnet add package Microsoft.EntityFrameworkCore.SqlServer + +ef工具 dotnet tool install --global dotnet-ef + +安装依赖包 dotnet add package Microsoft.EntityFrameworkCore.Design + +生成迁移文件 dotnet ef migrations add xxx + +将迁移文件同步到数据库 dotnet ef database update \ No newline at end of file diff --git "a/\346\235\216\346\200\235/20241225-\346\220\234\347\264\242\344\275\234\344\270\232.md" "b/\346\235\216\346\200\235/20241225-\346\220\234\347\264\242\344\275\234\344\270\232.md" new file mode 100644 index 0000000..29dde23 --- /dev/null +++ "b/\346\235\216\346\200\235/20241225-\346\220\234\347\264\242\344\275\234\344\270\232.md" @@ -0,0 +1,23 @@ + +``` +if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['query'])) { + $query = $_GET['query']; + $results = Model::search($query); + render('search_results', ['results' => $results, 'query' => $query]); +} +``` +``` +Models +class Model { + public static function search($query) { + + return Database::query("SELECT * FROM items WHERE name LIKE ?", ['%' . $query . '%']); + } +} +``` +``` +
+``` \ No newline at end of file diff --git "a/\346\235\216\346\200\235/20241226-\347\254\224\350\256\260.md" "b/\346\235\216\346\200\235/20241226-\347\254\224\350\256\260.md" new file mode 100644 index 0000000..970daa6 --- /dev/null +++ "b/\346\235\216\346\200\235/20241226-\347\254\224\350\256\260.md" @@ -0,0 +1,29 @@ + +``` +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); + // 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