如何使用EntityFramework Code First FluentAPI的bool属性设置默认值?

就像是:

Property(l => l.PropertyFlag).HasColumnType("bit").DefaultValue(1);

最佳答案

好消息,现在代码首先支持这一点。在生成的迁移的“Up()”方法中,使用以下语法指定默认值:

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

MSDN for "AddColumn" method

关于c# - EF6.X中的EntityFramework代码第一个FluentAPI默认值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20199382/

10-11 22:17
查看更多