EF Core 2.0 - Cannot add a new column to a specific table/class

0

we recently upgraded our ASP.Net Project to core 2.0 (which includes EF Core 2.0 for sure). Everything is working so far and I even changed some tables in DB with new migrations etc... everything worked... But now I have one table in which I have to add a simple column "MenuReqRole" at then end of the table. This is the class cfgPageMenuItems:

[Key]
[MaxLength(10)]
public string MenuArea { get; set; }
[Key]
[Required]
public int MenuOrderId { get; set; }
[Required]
public string MenuHeaderEntry { get; set; }
[Required]
public string MenuDescription { get; set; }
[Required]
public string MenuClickLink { get; set; }
public string MenuImageLink { get; set; }
//the new field   
public string MenuReqRole { get; set; }

When I now try to run Add-Migration in Package Manager Console it errors out with the following message:

Add-Migration MenuRoleAdjust2 -Context MyDbContext
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [c].[MenuArea], [c].[MenuOrderId], [c].[MenuClickLink], [c].[MenuDescription], [c].[MenuHeaderEntry], [c].[MenuImageLink], [c].[MenuReqRole]
      FROM [cfgPageMenuItems] AS [c]
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'MenuReqRole'.
It looks like it is trying to make a sql statement on DB(??) including this new column already... ok....just to be sure - this is the definition in the MyDbContextModelSnapshot.cs - no column MenuReqRole in the definition:

modelBuilder.Entity("MyApp.Config.cfgPageMenuItems", b =>
{
    b.Property<string>("MenuArea")
      .HasMaxLength(10);
    b.Property<int>("MenuOrderId");
    b.Property<string>("MenuClickLink")
      .IsRequired();
    b.Property<string>("MenuDescription")
      .IsRequired();
    b.Property<string>("MenuHeaderEntry")
      .IsRequired();
    b.Property<string>("MenuImageLink");
    b.HasKey("MenuArea", "MenuOrderId");
    b.ToTable("cfgPageMenuItems");
});

I am confused - also since this only happens with this one table (until now). Anyone any idea what this could have caused EF to freak out? Any help appreciated!!!!

Thanks, Jan

c#
asp.net
asp.net-core-2.0
ef-migrations
ef-core-2.0
asked on Stack Overflow Apr 20, 2018 by Jan1409

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0