在一个旧的应用程序,大部分的字符串属性不能为空,需要的String.Empty有一个默认值。
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 looking for a way to do this using the fluent configuration interface:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Properties<string>().Configure(c =>
{
c.HasMaxLength(255);
if (!c.ClrPropertyInfo.IsDefined(typeof (NullableAttribute), false))
{
c.IsRequired();
// I want to set a default value (string.empty) here.
}
}
有没有办法做到这一点还是我注定要初始化所有字符串的实体构造?
Is there any way to do this or I'm doomed to initialize all strings in the entity constructors?
现在的答案是是:
AddColumn("[table name]", "[column name]", c => c.Boolean(nullable: false, defaultValue: false));
上一篇:如果左操作数的?运营商不为空,不正确的操作得到评估?操作、不正确、为空、运营商
下一篇:为什么实体框架6.1.3扔&QUOT;未能加载类型“System.Data.Entity.Infrastructure.TableExistenceChecker'&QUOT;实体、框架、加载