Upgrade to EF 6.1.1 makes effect of [NotMapped] disappear

Solved by first uninstall and then reinstalling EF on all projects in the solution.

I think it was some mismatch in .NET versions for some projects when i upgraded to EF6 the first time which made the system take the [NotMapped] annotaition from the wrong assembly (.NET instead of EF).

This led me to it: http://social.msdn.microsoft.com/Forums/en-US/2d682be0-daca-45c4-ad76-5885acc6004f/possible-bug-with-inheritance-and-notmapped?forum=adodotnetentityframework

...and most the line: "If you use the new annotations from the System.ComponentModel.DataAnnotations.dll assembly in .NET 4.5 they will not be processed by Code First."


I also think that there is some mismatch with the .NET version and EF6, which made the program take the [NotMapped] annotation from a wrong assembly.

In particular, the problem is on the use of these two references: System.ComponentModel.DataAnnotations; System.ComponentModel.DataAnnotations.Schema.

I noted that, in this situation, we can not use both reference on same class file, because the NotMapped attribute will be assigned to a different dll of the expected. Even if you assign one of this reference in the code without putting the directive using (putting the complete reference on the attribute declaration, for instance), the program will still have this bug.

To solve this problem, I removed the reference System.ComponentModel.DataAnnotations from the class, leaving only the System.ComponentModel.DataAnnotations.Schema reference to use the NotMapped attribute. And to supply the miss of the first reference (form validation actions), I implemented the validation on the client-side (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; }

Late to the party, but I had this case:

using System.ComponentModel.DataAnnotations;//I needed this for [Key] attribute on another property
using System.ComponentModel.DataAnnotations.Schema;//this one is for [NotMapped]
...
[ScriptIgnore]
[NotMapped]
public System.Timers.Timer Timer { get; set; }

This would generate outrageous stuff like:

AddColumn("dbo.mytable", "Timer_AutoReset", c => c.Boolean(nullable: false));
AddColumn("dbo.mytable", "Timer_Enabled", c => c.Boolean(nullable: false));
AddColumn("dbo.mytable", "Timer_Interval", c => c.Double(nullable: false));

Experimenting with this I came to the conclusion that [NotMapped] is ignored if there is another attribute on the column. If it is possible - in my case it was - remove it and [NotMapped] won't be ignored.