保存

时间:2015-04-24 18:44:10

标签: javascript angularjs breeze

我得到" 500(内部服务器错误)基础错误为空"当我想保存我创建的实体时出现错误消息。

方案

  • 用户打开一个模态窗口,可以在其中创建/编辑博客条目
  • 他可以选择标签
  • 他也可以创建新标签
  • 如果有一个尚未存在的标签,那么系统会自动创建

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

我找到了找到缺陷的方法

  • 仔细检查代码 - 完成
  • 检查缓存 - 已完成 - 已禁用
  • 谷歌搜索 - 完成 - 这似乎是一个非常罕见的问题
  • 将代码放入控制器中是否存在范围问题 - 完成 - 结果是相同的
  • 检查REST控制器,它在71天前上次更改,但是,在其他情况下它运行良好
  • 睡觉...有时它有帮助 - 完成,它很棒但它没有帮助
  • 重启机器 - 完成 - 没有
  • 我想我的想法用完了......

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

此功能由ngTags输入内容的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];
                    }
                });
            });
        }

Controller调用服务方法:

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()"

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

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

现在,它工作正常。

这是改变:

enter image description here