1

Thanks in advance, I have been using code first with EF-DB migration in my project.

The challenge I am having is now I want to add a property in my Class which should only be long to the class and not Create a database table-column. I have tried setting scaffolding off and even setting the column as computed column. However when I run the Add-Migration "XYZ" it keeps creating that column.

//Class

    [ScaffoldColumn(false)]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
    public Nullable<int> Counter { get; set; }

// Migration

  public override void Up()
  {
       AddColumn("dbo.Registers", "Counter", c => c.Int());
  }
Sanj
  • 3,770
  • 6
  • 26
  • 31

1 Answers1

2

If you don't want Entity Framework to generate a database column for something, you can add the [NotMapped] attribute to that property, and it will be ignored.

anaximander
  • 7,083
  • 3
  • 44
  • 62
  • according to [https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application] it was not necessary, but it seems to be... thank you so much – Thiago Melo Jan 18 '17 at 16:47