Invalid Column name when using savechanges() in entity framework ef-database-first entity-framework entity-framework-6 sql-server


So here's the situation: I changed the PK for one of my tables, the database schema, and I erased everything connected to the previous PK (FK reference in another tables).

However, I encounter this issue when I use the savechanges() function to introduce a new object.

ex = {"An error occurred while updating the entries. See the inner exception for details."}

The internal exception is

InnerException = {"Invalid column name 'Audit_ID'."}

The old PK is the Audit ID.

This When attempting to put data into a database using SQL, "Invalid column name" appears. has been tested by me.

this 32-zzz-zzz

This is a zzz-39 zzz

nothing worked to fix my problem, so I erased my whole edmx and made a new one, but it didn't help either.

ps: I'm using a database-first strategy.

5/23/2017 12:08:44 PM

Accepted Answer

9/23/2016 2:24:27 AM

Popular Answer

In certain instances, we discovered that declaring the database components in the context resolved the problem.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
            modelBuilder.Entity<EntityNameInModel>().ToTable("table_in_database").HasKey(ats =>;
            modelBuilder.Entity<EntityNameInModel>().Property(ats => ats.user_name).HasColumnName("user_name");

Every schema, table, and field must be defined in this manner, but once you do, you'll have complete control over your code. Good fortune!

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow