ASP.NET MVC another entity of the same type already has the
ASP.NET MVC项目?Repository层中,Update、Delete总是失败 another entity of the same type already has the same primary key value在项目里的Repository层中的涉及到数据的update方法总是报错,delete时有时也会报错,报的错误是 Attaching an entity of type 'Model.Diary' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate. ? 按字面意思看,发生异常的原因在于已经存在了一个实体与要进行操作的实体存在相同的主键,相互冲突。 解决方案:
Stackflow上也有一篇文章这样的问题,传送门 博客园上也有一篇,解决方案,传送门 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET Core应用的错误处理[4]:StatusCodePagesMiddlewar
- asp.net – IIS 7:将所有请求重定向到Default.aspx
- asp.net – 无法在动态创建的System.Web.UI.WebControl上使
- asp.net-mvc-3 – MVC3重定向到ajax调用后的动作
- asp.net – LINQ to SQL Web应用程序最佳实践
- asp.net – 如何预编译Web应用程序项目?
- asp.net – 如何从WCF客户端拦截raw soap request / respon
- asp.net-mvc – 我可以在MVC3中的Html.LabelFor中添加一个C
- ASP.NET httpRedirect:重定向所有页面,除了一个
- asp.net-mvc-4 – 复杂模型上的MVC Html.DisplayNameFor
- asp.net-mvc – ASP.NET WEB API将DateTime作为U
- 是否有开源的Asp.net会员管理GUI(如netwebadmin,
- asp.net – 为什么我们应该通过部分视图使用MVC
- asp.net – 如何正确对齐一个Gridview列的标题
- asp.net – HttpContext.Current.User为空,即使W
- asp.net – 网络负载平衡方案的会话状态
- asp.net – 如何使Owin自主主机支持Json输出?
- asp.net – ORA-01036:非法变量名/号C#(SqlData
- asp.net – HttpContext.Current.Server null
- asp.net-mvc – 无法在实体框架模型中的MVC 4模板