我得到" 500(内部服务器错误)基础错误为空"当我想保存我创建的实体时出现错误消息。
方案:
系统要保存新标记时发生错误。我真正没有得到的是哪个数组是空的?!如果我写出新创建的实体,那么我看到一个健康的实体由breeze创建并且没有空值,除了一个(博客描述字段,但它不是必填字段)
我找到了找到缺陷的方法:
这是代码。没什么新鲜的。像这样的代码在应用程序的其他地方没有任何问题。
此功能由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()"
提前感谢您的帮助!
答案 0 :(得分:1)
我找到了。我犯了两个错误。
现在,它工作正常。
这是改变: