Breeze 底层数组在保存时为空错误

Breeze underlying array is null error at save

当我想保存我创建的实体时,收到“500(内部服务器错误)基础错误为空”错误消息。

场景:

系统要保存新标签时出现错误。我真正不明白的是哪个数组为空?!如果我写出新创建的实体,那么我会看到一个由 breeze 创建的健康实体并且没有空值,除了一个(博客描述字段,但它不是必填字段)

我做了什么来找到缺陷:

这是代码。没有什么新鲜事。这样的代码在应用程序的其他地方没有任何问题。

这个函数被ngTags-input东西的onTagAdding方法调用,它被放在一个服务中。

function onTagAdding(tag)
        {
            console.log("ontagadding");
            var select = 'id, name';
            var p = new Predicate('name', FilterQueryOp.Equals, tag.name);

            datacontext.tag.getAll(select, p).then(function (result)
            {
                if (result.length < 1)
                {
                    //add new tag
                    var newTag = datacontext.tag.create();
                    newTag.name = tag.name;
                    console.log('tag ontagadding', tag);
                    console.log('newTag  ontagadding', newTag);
                }

                datacontext.save().then(function (saveResult)
                {
                    console.log('saved tag  ontagadding');
                    if (typeof (saveResult) !== 'undefined')
                    {
                        lastSavedTag = saveResult.entities[0];
                    }
                });
            });
        }

控制器调用服务方法:

function onTagAdding(tag)
        {
            dataServiceTagHelper.onTagAdding(tag);
        }

请求负载:

"entities": [{
    "Id": -1,
    "Name": "sdfsdfsdf",
    "Desc": null,
    "entityAspect": {
        "entityTypeName": "Tag:#SayusiAndo.DiLib.Model.Model.Db.Model.Blog",
        "defaultResourceName": "Tags",
        "entityState": "Added",
        "originalValuesMap": {

        },
        "autoGeneratedKey": {
            "propertyName": "Id",
            "autoGeneratedKeyType": "Identity"
        }
    }
}],
"saveOptions": {

}

这是完整的错误信息:

Error: [DiLib Error]  save failed!The underlying array is null.
    at createError (http://dev.dilib.local/ui/scripts/breeze.debug.js:15821:15)
    at handleHttpError (http://dev.dilib.local/ui/scripts/breeze.debug.js:15811:15)
    at Object.breeze.AbstractDataServiceAdapter.proto.saveChanges.ajaxImpl.ajax.error (http://dev.dilib.local/ui/scripts/breeze.debug.js:15687:9)
    at errorFn (http://dev.dilib.local/ui/scripts/breeze.debug.js:16026:14)
    at http://dev.dilib.local/ui/scripts/angular.js:9415:11
    at processQueue (http://dev.dilib.local/ui/scripts/angular.js:13248:27)
    at http://dev.dilib.local/ui/scripts/angular.js:13264:27
    at Scope.$get.Scope.$eval (http://dev.dilib.local/ui/scripts/angular.js:14466:28)
    at Scope.$get.Scope.$digest (http://dev.dilib.local/ui/scripts/angular.js:14282:31)
    at Scope.$get.Scope.$apply (http://dev.dilib.local/ui/scripts/angular.js:14571:24)

服务器端:

StackTrace: "   at System.ArraySegment`1.System.Collections.IEnumerable.GetEnumerator()
↵   at System.Data.Entity.Core.Objects.EntityEntry.TakeSnapshotOfRelationships()
↵   at System.Data.Entity.Core.Objects.ObjectContext.AddObject(String entitySetName, Object entity)
↵   at Breeze.ContextProvider.EF6.EFContextProvider`1.AddObjectStateEntry(EFEntityInfo entityInfo)
↵   at Breeze.ContextProvider.EF6.EFContextProvider`1.ProcessEntity(EFEntityInfo entityInfo)
↵   at Breeze.ContextProvider.EF6.EFContextProvider`1.ProcessSaves(Dictionary`2 saveMap)
↵   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 SayusiAndo.DiLib.Service.WebApi.Controllers.Breeze.DiLibController.SaveChanges(JObject saveBundle) in c:\PROJECTS\sayusiando.visualstudio.com\DiLib\Dev\branches\DiLib-Dev\src\DigitalLibrary\App\DiLib\Service\DiLib.Service.WebApi\Controllers\Breeze\DiLibController.cs:line 29
↵   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.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
↵   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
↵   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
↵   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
↵   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
↵   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
↵   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
↵--- End of stack trace from previous location where exception was thrown ---
↵   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
↵   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
↵   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

提前感谢您的帮助!

我找到了。我犯了两个错误。

  • 当我为我的对象模型创建 C# 类 时,我想我需要一个数组来存储 BlogEntryTags,所以我输入 "array" 并按回车键。 Resharper 试图提供帮助,因此它放置了一个 ArraySegment 而不是 List。到目前为止它没有任何缺陷,因为我没有使用应用程序的这一部分。
  • 当我检查可能的问题时,我并没有检查 breeze 和 db 之间所有可能的问题。

现在,一切正常。

更改如下: