EF5 Code First - Changing A Column Type With Migrations

后端 未结 3 1949
长发绾君心
长发绾君心 2020-11-30 02:33

I am new to EF5 Code First and I\'m tinkering with a proof-of-concept before embarking on a project at work.

I have initially created a model that looked something l

3条回答
  •  悲哀的现实
    2020-11-30 02:45

    Based on @JustAnotherUserYouMayKnow's answer, but easier.

    Try firstly execute Sql() command and then AlterColumn():

    Sql(@"
        UPDATE dbo.People
        SET Location =
            CASE Location
                WHEN 'London' THEN 1
                WHEN 'Edinburgh' THEN 2
                WHEN 'Cardiff' THEN 3
                ELSE 0
            END
        ");
    AlterColumn("dbo.People", "Location", c => c.Int(nullable: false));
    

提交回复
热议问题