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

前端 未结 5 1958
梦毁少年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:40

    I found that just using Auto-Property Initializer on entity property is enough to get the job done.

    For example:

    public class Thing {
        public bool IsBigThing{ get; set; } = false;
    }
    

提交回复
热议问题