接着上一篇。在MyEFTestContext 类中添加这个方法
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity
.Property
}
执行add-migration 之后,会有迁移文件生成
public partial class shadow : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn
name: "LastUpdated",
table: "Blog",
nullable: false,
defaultValue: new DateTime(, , , , , , , DateTimeKind.Unspecified));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastUpdated",
table: "Blog");
}
}
可以看到,update-database 之后,会在数据库中添加一个字段,但是不会EF 一般用的时候,不会访问到。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章