0
I upgraded the Entity Framework version from 5 to 6 in my project, and Context.Savechanges from the Data Repository stopped working only in some cases.
I found that using Dataannotation in the properties of my model that contained the [Notmapped] attribute were causing an exception in Dbentityvalidation.
Commenting on these validations started to work 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; }
}
}
Someone has a solution to this case?