问题很简单,我将用户名属性的默认长度(32)修改为 500,但似乎代码被固定为 32。知道为什么会发生这种情况吗?
AbpUsers 的用户名字符串长度:
public class User : AbpUser<User>
{
[MaxLength(500)]
public override string UserName { get; set; }
}
这已成功更新了 db UserName 长度。
但是当我打电话
CheckErrors(await UserManager.CreateAsync(user));
它会返回:
System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities.
困扰我的是SaveChanges无法捕捉到这种异常:
public override int SaveChanges()
{
try
{
return base.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
}
您的帮助将不胜感激!