Unable to update the EntitySet 'T_JsAPI' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
前几天使用EF6的Db First模式改造了支付中心的数据访问层,废弃了ado.net。 同时,使用T4把实体类生成到了model层的PO目录下。
今天在db里新建了一张表,在edmx文件里更新模型(右键菜单:从数据库更新模型... / Update Models),并运行T4工具生成了新的实体。
完成bll以及相关调用后,测试发现ef抛出了如下异常:
System.Data.Entity.Infrastructure.DbUpdateException: Unable to update the EntitySet 'T_JsAPI' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. --->
System.Data.Entity.Core.UpdateException: Unable to update the EntitySet 'T_JsAPI' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
在 System.Data.Entity.SqlServer.SqlGen.DmlSqlGenerator.ExpressionTranslator.Visit(DbScanExpression expression)
在 System.Data.Entity.SqlServer.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, SqlGenerator sqlGenerator, List`1& parameters, Boolean generateReturningSql, Boolean upperCaseKeywords, Boolean createParameters)
在 System.Data.Entity.SqlServer.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, SqlVersion sqlVersion, List`1& parameters, CommandType& commandType, HashSet`1& paramsToForceNonUnicode)
在 System.Data.Entity.SqlServer.SqlProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
在 System.Data.Entity.SqlServer.SqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
在 System.Data.Entity.Core.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
在 System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(Dictionary`2 identifierValues)
在 System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
在 System.Data.Entity.Internal.InternalContext.SaveChanges()
--- 内部异常堆栈跟踪的结尾 ---
在 System.Data.Entity.Internal.InternalContext.SaveChanges()
在 PaymentBLL.JsApiBLL.Add(T_JsAPI entity)
在 PaymentBLL.InitJSAPIService.ConvertDTO2ExternalModel(JSPayResponseDTO dto, JSPayRequestModel reqModel)
在 PaymentBLL.InitJSAPIService.InitJSAPI(JSPayRequestModel reqModel)
网上查阅一番后,发现是由于疏忽未给数据表设置pk导致的。 给表加上主键后问题就解决了。If Entity Framework can't figure out the primary key, it will generate a SELECT statement but it won't be able to create the according INSERT, UPDATE and DELETE statements.(如果EF找不到pk,它将生成一个selelct语句,但不会生成相应的增删改语句)
reference:http://stackoverflow.com/questions/12316711/unable-to-update-the-entityset-because-it-has-a-definingquery
Unable to update the EntitySet 'T_JsAPI' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.的更多相关文章
- EntityFramework错误:Unable to update the EntitySet because it has a DefiningQuery
错误截图: 解决方法: 在所操作的数据库表中添加一个主键即可解决此问题
- [转]使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://repo1.maven.org/maven2 。
使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://re ...
- Vs打包工程 错误: Unable to update the dependencies of the project (转)
Setup Project 错误: Unable to update the dependencies of the project 在VS2010中编译包含安装工程的解决方案提示错误:Unable ...
- MySQL安装问题:Unable to update security settings解决方案
主要问题还是之前装过,卸载的时候卸载不干净导致的. 如下: 安装到最后出现: Unable to update security settings. Access denied for user 'r ...
- Unable to update index for central
Unable to update index for central http://repo1.maven.org/maven2/ 就是这句,myeclipse启动后控制台输出这句话:解决办法:1.在 ...
- git pull报“unable to update local ref”解决方案
使用git pull拉取代码的时候,无法拉取最新代码,报"unable to update local ref"错误. 除了重新clone一份代码外,还可以使用如下解决方案: 1. ...
- git pull fails “unable to resolve reference” “unable to update local ref”
问题 由于有人rebase了分支,或者不知道怎么搞的.其他人拉取代码的时候,发现拉不下来. >git fetch error: cannot lock ref 'refs/remotes/ori ...
- 解决eclipse安装maven的问题:Unable to update index for central|http://repo1.maven.org/maven2
问题产生如下:因为单位使用了过滤,访问Internet时,超过10M的内容就拒绝.因为maven插件在初始时,需要下载Maven的index文件,这个文件比较大,有38M多,下载不成功.所以造成使用M ...
- Unable to update index for central http://repo1.maven.org/maven2/ 解决方法
不知道什么原因 MyEclipse(eclipse) 中的 maven 插件突然不能用了,修改 pom.xml 无任何反应 控制台报 Unable to update index for centra ...
随机推荐
- 删除一个cjson导致系统死机
一个未使用,未分配的cjson指针应该被删除,如果尝试删除一个 未分配,未启用的cjson将导致内存出错,死机.
- 内部排序->基数排序->链式基数排序
文字描述 基数排序是和前面各类排序方法完全不相同,前面几篇文章介绍的排序算法的实现主要是通过关键字间的比较和移动记录这两种操作,而实现基数排序不需要进行记录关键字间的比较.基数排序是一种借助多关键字排 ...
- ORACLE managed file(OMF)
ORACLE managed file (OMF) Oracle自动创建和删除OMF文件 不用操心文件的命名约定 在手动管理文件时容易错误删除数据文件(OMF降低这种风险) Oracle自动删除不再需 ...
- BouncyCastle 密钥转换 - Java
转自: https://blog.csdn.net/a351945755/article/details/63707040 1. PKCS#8 转 PKCS#1 You will need Bounc ...
- Java 生成三位随机数
调用这个Math.Random()函数能够返回带正号的double值,该值取值区间是[0.0,1.0),注意,它是左闭右开区间.返回值是一个伪随机选择的数,在该范围内(近似)均匀分布. 如果生成三位随 ...
- 使用github的srs代码,搭建 RTMP_Server
1. 搭建RTMP服务器 1> 获取开源代码SRS. git clone https://github.com/ossrs/srs 下载源码后,按照如下文档安装https://github.co ...
- 从网络上筛选"流媒体"的相关文章
1> 雷神的博客专栏https://blog.csdn.net/leixiaohua1020 [总结]FFMPEG视音频编解码零基础学习方法https://blog.csdn.net/leixi ...
- php 关于时间函数
1. 设置时区 date_default_timezone_set() 和 putenv() 让时间安全地设置就,输入如下代码: date_default_timezone_set('UTC'); / ...
- ES6 --- JS异步编程的几种解决方法及其优缺点
导言: 我们都知道 JS 是单线程的,这也正是异步编程对于 JS 很重要的原因,因为它无法忍受耗时太长的操作.正因如此有一系列的实现异步的方法. 方法一 setTimeout 常用于:定时器,动画 ...
- Innodb semi-consistent 简介
A type of read operation used for UPDATE statements, that is a combination of read committed and con ...