1
因此,我使用ASP.NET Identity +實體框架,每當我從代碼生成數據庫時,許多列類型都是非常重的NCLOB。強制實體框架不使用NCLOB數據類型
現在有幾種方法來修改類型的列的如HasColumnType
方法,或通過設置StringLength屬性或通過配置模型構建器給予HasMaxLength
attribue對於那些還沒有的話誰。
身份問題在於某些專門用於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
已被設置爲某個值,但即使如此沒有改變。
有沒有解決方法,它不會改變?
謝謝!