在Package Manager Console 中运行命令Enable-Migrations

Entity framework 更改模型,新增表

再次运行可以更新

抄袭

 在实体类中增加一个属性以后,执行 Update-Database 命令 ,可以更新数据库。

二 新增表:

  新建类:

 

    public class MeasureResult
    {
        public int Id { get; set; }
        public int CableId { get; set; }
        public int LineId { get; set; }
        public int OperatorId { get; set; }
        public double Result { get; set; }
        public DateTime Time { get; set; }
    }

  在DbContext中 添加上下文:

    public class EfDbContext:DbContext
    {
        public DbSet<Cable> Cables { get; set; }
        public DbSet<CableLine> CableLines { get; set; }
        public DbSet<MeasureResult> MeasureResults { get; set; }
    }

 

应用Migration生成数据库

使用命令在 package manager console:

  1  Enable-Migrations

  2  Add-Migration Init -Verbose

  执行完这一步以后在工程的 MIGrations文件夹下会生成一个 cs文件,在其中只保留需要新增的表。

  3  Update-Database -Verbose 

  执行完以后 数据库中会生成相应的数据库表

 

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2021-09-21
  • 2021-05-31
  • 2022-01-18
  • 2021-09-27
  • 2022-01-09
相关资源
相似解决方案