How can set a default value constraint with Entity Framework 6 Code First?

前端 未结 5 1959
梦毁少年i
梦毁少年i 2020-12-03 01:02

In a legacy app, most string properties can\'t be null and need to have a default value of string.empty.

I know it\'s possible to do this with migrations, but I\'m l

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 01:20

    Now the answer is Yes:

    AddColumn("[table name]", 
              "[column name]", 
              c => c.Boolean(nullable: false, defaultValue: false));
    

提交回复
热议问题