在 ASP.NET Core 中,可以通过迁移和更改模型类来更改模型的模式。要更改模型的模式,必须使用 Entity Framework Core (EF Core)。下面是更改模型的模式的步骤:
Add-Migration NewMigrationName
其中,NewMigrationName 是您想要命名新迁移的名称。
public class Student
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public DateTime DateOfBirth { get; set; }
public string Address { get; set; }
public bool IsActive { get; set; }
// 新属性
public string Gender { get; set; }
}
Update-Database
此命令将更新数据库架构以反映新的模型更改。
现在,您已经成功地更改了 ASP.NET Core 中模型的模式。