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

jcg*_*eza 1 entity-framework database-migration sql-scripts

我首先使用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 the old 
        //column is dropped
        DropColumn("dbo.PatientMedicalDataEntities", "Weight");
    }
Run Code Online (Sandbox Code Playgroud)

我需要做的是添加一些sql脚本,将数据从dbo.PatientMedicalDataEntities中的'Weight'列移动到新创建的表dbo.HistoricalWeightEntities中的Weight列,并插入ID值(键),这是一个Guid并删除列之前的相应外键.有人可以告诉我这是怎么做的是sql?

先感谢您

Rap*_*aus 6

它应该是那样的(恩诺你想用Date栏做什么)

Sql("INSERT INTO HistoricalWeightEntities(Id, Weight, PatientMedicalDataId) "+
    "SELECT newid(), Weight, <theForeignKeyColumn> from PatientMedicalDataEntities"); 
Run Code Online (Sandbox Code Playgroud)