How to ignore a property when using Entity Framework Code First [duplicate]

Solution 1:

Add the [System.ComponentModel.DataAnnotations.Schema.NotMapped] attribute to the property.

Solution 2:

Per the accepted answer and similar question/answer, in addition to [NotMapped] you can also specify it using the Fluent API:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty);
   base.OnModelCreating(modelBuilder);
}

Solution 3:

[NotMapped] is the short version if you like conciseness. And of course, you would add:

using System.ComponentModel.DataAnnotations.Schema;

to your class.