Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade to EF 6.1.1 makes effect of [NotMapped] disappear

I have upgraded from EF 4.3.1 to 6.1.1 and now it seems like the annotation [NotMapped] is useless. Yes, i have change to correct assembly and everything looks fine on compilation.

Everywhere where [NotMapped] is present the property is handled as a domain property and i get an error that EF can't find the matching column in database.

Example:

private bool _authenticated = true;

        [NotMapped]
        public bool Authenticated
        {
            get { return _authenticated; }
            set { _authenticated = value; }
        }

Yes, it seems like i can work around this by adding...

 modelBuilder.Entity<User>().Ignore(x => x.Authenticated);

...but then, whats the use of [NotMapped] in EF6?

(Worked perfect before upgrade)

like image 607
Gruffalon Avatar asked Sep 03 '14 14:09

Gruffalon


1 Answers

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."

like image 98
Gruffalon Avatar answered Sep 30 '22 05:09

Gruffalon