在 EF 6 中我可以这样做:
modelBuilder
.Properties()
.Where(p => p.PropertyType == typeof(string) &&
p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0)
.Configure(p => p.HasMaxLength(2000));
因为 EF7 ModelBuilder 没有Properties()
函数,我如何在 EF7 中做同样的事情?
我认为这是 EF Core 中“仍然缺乏”的功能之一,并希望在以后的版本中添加它。
在那之前,我可以建议的最接近的(对于 v1.1.0)如下:
foreach (var p in modelBuilder.Model
.GetEntityTypes()
.SelectMany(t => t.GetProperties())
.Where(p => p.ClrType == typeof(string) && p.GetMaxLength() == null))
{
p.SetMaxLength(2000);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)