zoukankan      html  css  js  c++  java
  • 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 INSERTUPDATE and DELETE statements.(如果EF找不到pk,它将生成一个selelct语句,但不会生成相应的增删改语句)

    reference:http://stackoverflow.com/questions/12316711/unable-to-update-the-entityset-because-it-has-a-definingquery

  • 相关阅读:
    C#的泛型的类型参数可以有带参数的构造函数的约束方式吗
    Object Pool
    链表排序(冒泡、选择、插入、快排、归并、希尔、堆排序)
    ASP.NET MVC应用程序使用axd格式文件
    框架设计--服务总线
    Mylyn
    不要问我能赚多少,当你问这句话的时候,你的思想还停留在给别人打工的阶段,我只是你的仓库,能挣多少得问你自己想挣多少(转)
    maven中如果使用本地jar
    君子和而不同,小人同而不和
    失去控制,并随之失去指挥
  • 原文地址:https://www.cnblogs.com/buguge/p/6723014.html
Copyright © 2011-2022 走看看