小编jcg*_*eza的帖子

EF5数据库迁移:如何移动数据

我首先使用EF5代码,现在我需要更新我的数据库,所以我启用了数据库迁移并添加了迁移,但生成的代码不是我需要的.这是代码:

public override void Up()
    {
        CreateTable(
            "dbo.HistoricalWeightEntities",
            c => new
                {
                    PatientMedicalDataId = c.Guid(nullable: false),
                    Id = c.Guid(nullable: false),
                    Weight = c.Single(nullable: false),
                    Date = c.DateTime(nullable: false),
                })
            .PrimaryKey(t => new { t.PatientMedicalDataId, t.Id })
            .ForeignKey("dbo.PatientMedicalDataEntities", t => t.PatientMedicalDataId, cascadeDelete: true)
            .Index(t => t.PatientMedicalDataId);

        AddColumn("dbo.PatientDataEntities", "PatientDataFilePath", c => c.String());
        //Here I need to move data from the old Weight column to the Weight column on the newly
        //created table and create the id (Guid) and the foreing key before …
Run Code Online (Sandbox Code Playgroud)

entity-framework database-migration sql-scripts

1
推荐指数
1
解决办法
3595
查看次数