简体   繁体   中英

Entity Framework not saving new column

I added a new column to an object, and used EF to update the model from the database.

Normally we do the following:

context.BulkInsert(records, GetBulkInsertOptions());
context.SaveChanges();

But this doesnt seem to work for the new column. If I do the following it works, but is obviously not ideal.

foreach (var r in records)
{
    context.MyDBObject.Add(r);
    context.Entry(r).State = EntityState.Modified;
    context.SaveChanges();
}

Can anybody shed some light on this? Additionally, if I erase the row in the database before it does a save, it will insert everything, except for the new column I added.

edit: Using Entity Framework v6.2.0 and EntityFramework.BulkInsert v6.0.3.8

edit 2: If I erase the row, and try to insert a new object using only the following

context.MyTable.Add(test);
context.SaveChanges()

This also inserts the object, but doesnt include my new column. This leads me to believe its more an error with EF and less with the BulkInsert as I alluded to previously.

The issue was caused by Triggers in the table in Mssql.

Doing context.Database.Log = Console.WriteLine; Helped us determine that Entity Framework was sending the right query to SQL. Testing the query in SQL showed that the new column wasn't being saved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM