I upgraded the Entity Framework version from 5 to 6 in my project, and the Data Repository Context.SaveChanges stopped working in only a few cases.
I found that using DataAnnotation in properties of my template that contained the [NotMapped] attribute were causing an exception in DbEntityValidation.
Commenting on these validations started working again.
using PROJETO.Helper.Generic;
using PROJETO.Helper.Resources;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PROJETO.Entity.Models
{
[Table("Users")]
public class User
{
[Key]
public int UserID { get; set; }
[Display(Name = "Usuário:")]
[Required(ErrorMessageResourceName = "UserNameRequired", ErrorMessageResourceType = typeof(CustomMessages))]
[StringLength(20, MinimumLength = 4, ErrorMessage = "O usuário deve conter no mínimo quatro caracteres e no máximo vinte!")]
public string UserName { get; set; }
[Display(Name = "Senha:")]
[Required(ErrorMessageResourceName = "PasswordRequired", ErrorMessageResourceType = typeof(CustomMessages))]
[StringLength(20, MinimumLength = 4, ErrorMessageResourceName = "PasswordLength", ErrorMessageResourceType = typeof(CustomMessages))]
[RegularExpression(@"^((?=.*[a-z])(?=.*[A-Z])(?=.*\d)).+$", ErrorMessageResourceName = "PasswordFormat", ErrorMessageResourceType = typeof(CustomMessages))]
[CustomValidation.NotEqual("CurrentPassword", ErrorMessageResourceName = "PasswordCompare", ErrorMessageResourceType = typeof(CustomMessages))]
[DataType(DataType.Password)]
public string Password { get; set; }
public string Roles { get; set; }
[NotMapped]
[Display(Name = "Senha Atual:")]
//[Required(ErrorMessageResourceName = "CurrentPasswordRequired", ErrorMessageResourceType = typeof(CustomMessages))]
[DataType(DataType.Password)]
public string CurrentPassword { get; set; }
[NotMapped]
[Display(Name = "Confirmar:")]
//[Required(ErrorMessage = "Confirme a senha!")]
//[Compare("Password", ErrorMessageResourceName = "PasswordConfirmCompare", ErrorMessageResourceType = typeof(CustomMessages))]
[DataType(DataType.Password)]
public string PasswordConfirm { get; set; }
[NotMapped]
[Display(Name = "Manter Conectado")]
public virtual bool RememberMe { get; set; }
}
}
Does anyone have a solution for this case?