sqllite 的数据库迁移功能有限制
1)新增如下model,执行数据库迁移不能成功,参考此链接“http://stackoverflow.com/questions/35797628/ef7-generates-wrong-migrations-with-sqlite”
初步判断有限制,所以删除数据库,删除迁移文件,重建数据库“http://www.atove.com/Article/Details/87E62DFDDBF9EC0C5350E7ACD43BADDF”(这篇文章是非.net core环境下的,实验无法成功,以后有空再实验)
using System; using System.ComponentModel.DataAnnotations; //手动高亮 namespace MvcMovie.Models { public class People{ public int ID { get; set; } // [Display(Name = "姓名")] public string Name { get; set; } // [Display(Name = "年龄")] public int Age { get; set; } } }
2)数据库OK
3)新增控制器PeopleController.cs,新增View目录“People”和视图文件Index.cshtml
public async Task<IActionResult> Index() { return View(await _context.People.ToListAsync()); }
@model IEnumerable<MvcMovie.Models.People> @{ ViewData["Title"] = "Index"; } <h2>ViewData["Title"]</h2> <p> <a asp-action="Create">Create New</a> </p> <table class="table"> <thead> <tr> <th> <!--Html.DisplayNameFor(model => model.Genre)--> @Html.DisplayNameFor( model => model.Name ) </th> <th> @Html.DisplayNameFor( model => model.Age ) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Age) </td> <td> <a asp-action="Edit" asp-route-id="@item.ID">Edit</a> | <a asp-action="Details" asp-route-id="@item.ID">Details</a> | <a asp-action="Delete" asp-route-id="@item.ID">Delete</a> </td> </tr> } </tbody> </table>
时间: 2024-10-16 10:55:47