Entity Framework Code First will auto-create a table in the database base based on the Model.
Is there an attribute that will avoid this?
Join Stack Overflow to learn, share knowledge, and build your career.
Entity Framework Code First will auto-create a table in the database base based on the Model.
Is there an attribute that will avoid this?
Add the [System.ComponentModel.DataAnnotations.Schema.NotMapped]
attribute to the property.
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);
}
[NotMapped]
is the short version if you like conciseness. And of course, you would add:
using System.ComponentModel.DataAnnotations.Schema;
to your class.