在我的模型中,我有一些用StringLength属性装饰的实体:
[StringLength(128)]
public string FirstName { get; set; }
我也以这种方式为所有字符串属性禁用了unicode:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Properties<string>().Configure(p => p.IsUnicode(false));
}
问题在于,在生成数据库模式时,所有用上述属性修饰的字符串属性都将忽略此设置,从而为相应的数据库列生成nvarchar数据类型。在这种情况下,禁用unicode的正确方法是什么?
似乎是新PropertyConventionConfiguration
API中的错误(或遗漏)。以下配置确实有效,因此可以作为解决方法:
modelBuilder.Properties<string>().Configure(x => x.HasColumnType("VARCHAR"));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句