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 ...
 
随机推荐
- 用U盘制作并安装WIN10 64位原版系统的详细教程(该方法应该适用于任何一版的原版操作系统)
			
https://www.cnblogs.com/Jerseyblog/p/6518273.html
 - 队列  Queue  JoinableQueue
			
from multiprocessing import Process, Queue def f1(q); for i in range(10): q.put(i) def f2(q): whl ...
 - vim中的ctrl+s导致的“假死”、无响应、不接受输入
			
有时候vim看到vim的光标在闪烁,但无法输入任何东西,最后只好结束终端了事. 这种现象,是windows用户在使用vim时经常犯的“错误”.在windows下,为了保护自己的劳动成果,ctrl+s已 ...
 - CCPC-Wannafly Winter Camp Day3 Div1 - 石头剪刀布 - [带权并查集]
			
题目链接:https://zhixincode.com/contest/14/problem/I?problem_id=211 样例输入 1 3 5 2 1 1 2 1 2 1 1 2 3 2 1 ...
 - 字母算术的python算法
			
据说Google出过一道题目:WWWDOT – GOOGLE = DOTCOM. 其中每个字母代表一个数字,数字不能重复,而且最高位的数字不能为0. 像这样的谜题被称为cryptarithms或者字母 ...
 - In abstract algebra, a congruence relation (or simply congruence) is an equivalence relation on an algebraic structure (such as a group, ring, or vector space) that is compatible with the structure in
			
https://en.wikipedia.org/wiki/Congruence_relation In abstract algebra, a congruence relation (or sim ...
 - PHP-之POSIX系列函数和兼容Perl系列函数比较
			
PHP有两种正则系列函数 POSIX 系列和兼容Perl系列的函数 在PHP大于5.3使用POSIX系列函数会报E_DEPRECATED 错误, POSIX系列函数在大于5.3版本不建议使用,PHP7 ...
 - xcode工程编译错误:一般错误总结
			
1.Apple LLVM 8.0 Error Group /’all-product-headers.yaml’ not found 最近升级了xcode打包后出现了个BUG,记录解决的方法. 现象: ...
 - [daily][grub2] grub2修改内核选项
			
以前, 我们就直接去修改 /boot/grub/grub.cfg 文件了. 其实这并不正确. 正确的做法是: 1. 修改 /etc/default/grub 文件. [root@dpdk ~]# c ...
 - [filesystem][archlinux][disk encryption][btrfs] btrfs
			
fork from here http://www.cnblogs.com/hugetong/p/6914248.html boot分区,MBR加密:https://wiki.archlinux.or ...