在实体框架中使用savechanges()时,列名无效 [英] Invalid Column name when using savechanges() in entity framework
问题描述
这就是问题所在,我更改了数据库架构,并更改了其中一个表的PK,并且删除了与旧PK(另一张表中的FK参考)相关的所有内容.
So here is the deal, I have changed my database schema, and changed the PK for one of my tables and I have removed everything related to the old PK (FK reference in another tables).
但是,当我使用savechanges()方法插入新实体时出现此异常
However I have this exception when I insert a new entity using savechanges() method
ex = {更新条目时发生错误.有关详细信息,请参见内部异常."}
ex = {"An error occurred while updating the entries. See the inner exception for details."}
内部异常是
InnerException = {无效的列名'Audit_ID'."}
InnerException = {"Invalid column name 'Audit_ID'."}
Audit_ID是旧的PK.
the Audit_ID is the old PK.
我已经尝试过了 无效列名称"尝试使用SQL将数据插入数据库时
什么也解决不了我的问题,所以当我删除整个edmx并创建了一个新的edmx时,它也无法正常工作.
and nothing solved my issue, so as I deleted my whole edmx and created a new one also it didn't work.
ps:我正在使用数据库优先方法
ps: I am using database first approach
推荐答案
由于问题实际上出在SQL Server数据库中,因此没有解决方案.
Non of the solutions worked because the problem was actually in the SQL server database.
我运行SQL Profiler并执行了程序insert语句,我发现错误出在表的触发器之一中,该触发器具有Previous列名,将其更改为新的PK并最终起作用.
I ran SQL Profiler and executed the program insert statement, I found out that the error is in one of the table's triggers which has the Previous column name, changed that to the new PK and it finally worked.
因此,如果有人遇到类似问题,则帖子中的上述链接可能会有所帮助,或者您应该检查问题是否确实在数据库服务器上发生.
So if anyone have a similar problem, the above links in the post might help or you should check if the problem was actually happening the Database server.
这篇关于在实体框架中使用savechanges()时,列名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!