简体   繁体   English

实体框架不保存新列

[英]Entity Framework not saving new column

I added a new column to an object, and used EF to update the model from the database.我向 object 添加了一个新列,并使用 EF 从数据库中更新了 model。

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编辑:使用实体框架 v6.2.0 和 EntityFramework.BulkInsert v6.0.3.8

edit 2: If I erase the row, and try to insert a new object using only the following编辑 2:如果我删除该行,并尝试仅使用以下内容插入一个新的 object

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

This also inserts the object, but doesnt include my new column.这也会插入 object,但不包括我的新列。 This leads me to believe its more an error with EF and less with the BulkInsert as I alluded to previously.这让我相信它更多的是 EF 的错误,而不是我之前提到的 BulkInsert 的错误。

The issue was caused by Triggers in the table in Mssql.该问题是由 Mssql 中的表中的触发器引起的。

Doing context.Database.Log = Console.WriteLine;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.帮助我们确定 Entity Framework 正在向 SQL 发送正确的查询。测试 SQL 中的查询表明未保存新列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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