通过Breeze.js保存新实体在AutoGeneratedKey上出错

时间:2014-01-02 21:48:04

标签: entity-framework asp.net-web-api breeze

我通过Breeze,WebAPI和Entity Framework将我的实体保存到数据库时出错。我检查了我的breeze客户端,创建了新的实体。在我的WebAPI控制器SaveChanges方法中,我检查了saveBundle JObject,它看起来也是oK。

我得到的错误是:

An exception of type 'System.MissingFieldException' occurred in Breeze.ContextProvider.dll but was not handled in user code`

Additional information: Field not found: 'Breeze.ContextProvider.EntityInfo.AutoGeneratedKey'.`



   at Breeze.ContextProvider.EF6.EFContextProvider`1.SaveChangesCore(SaveWorkState saveWorkState)
   at Breeze.ContextProvider.ContextProvider.OpenAndSave(SaveWorkState saveWorkState)
   at Breeze.ContextProvider.ContextProvider.SaveChanges(JObject saveBundle, TransactionSettings transactionSettings)
   at FCMA.BusinessFunctions.DataAccess.BusinessFunctionsRepository.SaveChanges(JObject saveBundle) in c:\_tfs\AppDev\Intranet\BusinessFunctions\dev\src\BusinessFunctions.DataAccess\BusinessFunctionsRepository.cs:line 22
   at CC.Web.Controllers.BreezeController.SaveChanges(JObject saveBundle) in c:\_tfs\AppDev\Intranet\BusinessFunctions\dev\src\BusinessFunctions\Controllers\BreezeController.cs:line 28
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

我的saveBundle对象是:

 ?   saveBundle
    {
      "entities": [
        {
          "Id": -1,
          "CpuCode": 469,
          "ActionCode": 1,
          "ApplicationTypeCode": 1,
          "Cif": 12121,
          "CustomerName": null,
          "SalesBranch": null,
          "StatusCode": 1,
          "FsoCode": "asd",
          "BaCode": "asd",
          "LpsCode": null,
          "Transfer": false,
          "LoanNbr": null,
          "LoanAmount": 123,
          "DatePackageRcvd": null,
          "DateDecision": null,
          "Comments": null,
          "CreatedBy": null,
          "DateTimeCreated": null,
          "UpdatedBy": null,
          "DateTimeUpdated": "2014-01-02T21:07:56.52Z",
          "entityAspect": {
            "entityTypeName": "Log:#FCMA.BusinessFunctions.Model",
            "defaultResourceName": "Logs",
            "entityState": "Added",
            "originalValuesMap": {},
            "autoGeneratedKey": {
              "propertyName": "Id",
              "autoGeneratedKeyType": "Identity"
            }
          }
        }
      ],
      "saveOptions": {}
    }
        base: {
      "entities": [
        {
          "Id": -1,
          "CpuCode": 469,
          "ActionCode": 1,
          "ApplicationTypeCode": 1,
          "Cif": 12121,
          "CustomerName": null,
          "SalesBranch": null,
          "StatusCode": 1,
          "FsoCode": "asd",
          "BaCode": "asd",
          "LpsCode": null,
          "Transfer": false,
          "LoanNbr": null,
          "LoanAmount": 123,
          "DatePackageRcvd": null,
          "DateDecision": null,
          "Comments": null,
          "CreatedBy": null,
          "DateTimeCreated": null,
          "UpdatedBy": null,
          "DateTimeUpdated": "2014-01-02T21:07:56.52Z",
          "entityAspect": {
            "entityTypeName": "Log:#FCMA.BusinessFunctions.Model",
            "defaultResourceName": "Logs",
            "entityState": "Added",
            "originalValuesMap": {},
            "autoGeneratedKey": {
              "propertyName": "Id",
              "autoGeneratedKeyType": "Identity"
            }
          }
        }
      ],
      "saveOptions": {}
    }
        Type: Object

我哪里做错了?任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:2)

事实证明,我需要为我的DataAccess项目提供更新版本的Breeze.Server.ContextProvider.EF6,如Nico Leguizamon指出他对链接上类似问题的回答:save changes using Breeze, web api, and entity framework 谢谢Nico