I also believe that there is some inconsistency with the versions of .NET and EF6, which caused the program to take the [NotMapped] annotation from the wrong assembly.
In particular, the problem is using these two links: System.ComponentModel.DataAnnotations; System.ComponentModel.DataAnnotations.Schema.
I noted that in this situation we cannot use both links in the same class file, because the NotMapped attribute will be assigned to another dll expected. Even if you assign one of these links in code without specifying a directive using (for example, to completely reference an attribute declaration), the program will still have this error.
To solve this problem, I removed the System.ComponentModel.DataAnnotations class reference from the class, leaving only the System.ComponentModel.DataAnnotations.Schema link to use the NotMapped attribute. And to provide the missing first link (form validation actions), I performed a client-side validation (using jquery + javascript).
using System; using System.Collections.Generic; //using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; public partial class Account { //[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo nome é obrigatório!")] //[System.ComponentModel.DataAnnotations.StringLength(50, ErrorMessage = "O campo nome deve possuir no máximo 50 caracteres!")] //[System.ComponentModel.DataAnnotations.Display(Name = "Nome")] public string Name { get; set; } //[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo nome é obrigatório!")] //[System.ComponentModel.DataAnnotations.StringLength(100, ErrorMessage = "O campo email deve possuir no máximo 100 caracteres!")] //[System.ComponentModel.DataAnnotations.Display(Name = "Email")] public string Email { get; set; } //[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo senha é obrigatório!")] //[System.ComponentModel.DataAnnotations.Display(Name = "Senha")] //[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Password)] [NotMapped] public string Password { get; set; } //[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo confirmação de senha é obrigatório!")] //[System.ComponentModel.DataAnnotations.Display(Name = "Confirmação da senha")] //[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Password)] //[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "A confirmação da senha está diferente da senha informada.")] [NotMapped] public string ConfirmPassword { get; set; }
source share