【发布时间】:2017-07-23 07:54:39
【问题描述】:
所以我使用的是 ASP.NET Identity + Entity Framework,每当我从代码生成数据库时,很多列类型都是非常重的 NCLOB。
现在有几种方法可以修改列的类型,例如 HasColumnType 方法或通过设置 StringLength 属性或通过配置模型构建器为尚未拥有它的人提供 HasMaxLength 属性。
identity 的问题是一些专门用于 ID 的列设置得比较晚。
所以在迁移文件中我有这个:
UserId = c.String(nullable: false, maxLength: 128),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Decimal(nullable: false, precision: 1, scale: 0),
PasswordHash = c.String(),
SecurityStamp = c.String(),
PhoneNumber = c.String(),
现在应用我在网上找到的这段代码后:
modelBuilder.Properties()
.Where(p => p.PropertyType == typeof(string) &&
p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0 )
.Configure(p => p.HasMaxLength(2000));
迁移代码变成这样:
UserId = c.String(nullable: false, maxLength: 2000),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Decimal(nullable: false, precision: 1, scale: 0),
PasswordHash = c.String(maxLength: 2000),
SecurityStamp = c.String(maxLength: 2000),
PhoneNumber = c.String(maxLength: 2000),
如果您注意到了,UserID 已经设置为某个值,但即便如此,它还是发生了变化。
有没有办法让它不改变?
谢谢!!!
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework oracle11g asp.net-identity