Migration problems with EntityFramework 7 and Data Annotations

I’m currently developing a new UWP app for Windows 10. A chance to try the new EntityFramewok 7 (RC2) with SQLite. 😉 Although it is still not final, it works very well. But there are still some strange things. I figured out a problem with the [NotMapped] Data Annotation. At some point I wasn’t able to create migrations anymore.

I tried to add an initial migration with:

Add-Migration Init

But all I got was an exception:

System.NullReferenceException: Object reference not set to an instance of an object.

Poking around in the dark, I tried to replace the Data Annotations with the Fluent-API in my DB-Context like this:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<MyClass>()
        .Ignore(e => e.PropertyToIgnore);
}

And finally everything worked again! The strange thing is, that not every [NotMapped] caused this problem!? Maybe this will be fixed in future releases… 🙂

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.