null id Orchard 存储库创建 Id 身份
null id Orchard repository creation Id identity on
我使用 Orchard 使用此代码创建一个新条目
_repository.Create(new GMapZonePartRecord {
Name = model.Name,
Description = model.Description,
Commune = model.Commune,
Quarter = model.Quarter,
Price = model.Price,
StartZoom = model.StartZoom,
StopZoom = model.StopZoom,
Color = model.Color,
GMapPartRecord = partRecord
});
其中 _repository 是 IRepository。
我的代码很久以前就可以工作,现在出现异常
我的列 id 是 migration.cs:
中的标识
SchemaBuilder.CreateTable("GMapZonePartRecord",
table => table
.Column<int>("Id", col => col.PrimaryKey().Identity())
.Column<string>("Name")
.Column<string>("Description")
.Column<string>("Color")
.Column<int>("GMapPartRecord_Id"));
错误详情如下:
null id in JooWeb.GMap.Models.GMapZonePartRecord entry(发生异常后不刷新Session)
问题描述:当前网络请求执行过程中出现未处理的异常。检查堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:NHibernate.AssertionFailure:JooWeb.GMap.Models.GMapZonePartRecord条目中的空id(发生异常后不刷新会话)
来源错误:
第 159 行:}
第 160 行:
第 161 行:return 条件
第 162 行:.List()
第 163 行:.Select(x => ContentManager.Get(x.ContentItemRecord.Id, _versionOptions != null && _versionOptions.IsDraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id) ))
源文件:c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs 行:161
堆栈跟踪:
[AssertionFailure: null id in JooWeb.GMap.Models.GMapZonePartRecord entry (don't flush the Session after an exception occurs)]
NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId(Object obj, IEntityPersister persister, Object id, EntityMode entityMode) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:111
NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues(Object entity, EntityEntry entry, EntityMode entityMode, Boolean mightBeDirty, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:81
NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:36
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:161
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:60
NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:30
NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:1182
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:1959
NHibernate.Impl.CriteriaImpl.List(IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:265
NHibernate.Impl.CriteriaImpl.List() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:276
Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs:161
Orchard.ContentManagement.ContentQuery`1.Orchard.ContentManagement.IContentQuery<T>.List() in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs:262
Orchard.Widgets.Filters.WidgetFilter.OnResultExecuting(ResultExecutingContext filterContext) +4348
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +193
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\Mvc\Routes\ShellRoute.cs:159
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9676252
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
谢谢大家的帮助,我真的不知道去哪里找。
编辑:
添加Nhibernate 3.3.X源后,发现检查失败的不是ContentItemRecord的空值。
有什么想法吗?
你永远不应该使用 Repository<TRecord>
来创建零件记录(你几乎不应该使用 Repository<TRecord>
,句点)。使用您的代码,您创建了与内容项不对应的孤立部分记录。相反,请使用 ContentManager
上的 API,它会负责为您创建所有关联记录。
为了调试,我从 https://github.com/nhibernate/nhibernate-core/tree/3.3.x 下载了 NHibernate 源代码
并发现空值不是像错误消息那样的 id 让我们思考而是 ContentItemRecord.
所以我只是在上面添加了新的值:
_repository.Create(new GMapZonePartRecord
{
Name = model.Name,
Description = model.Description,
Commune = model.Commune,
Quarter = model.Quarter,
Price = model.Price,
StartZoom = model.StartZoom,
StopZoom = model.StopZoom,
Color = model.Color,
GMapPartRecord = partRecord,
ContentItemRecord = new ContentItemRecord()
});
现在一切正常:)
我使用 Orchard 使用此代码创建一个新条目
_repository.Create(new GMapZonePartRecord {
Name = model.Name,
Description = model.Description,
Commune = model.Commune,
Quarter = model.Quarter,
Price = model.Price,
StartZoom = model.StartZoom,
StopZoom = model.StopZoom,
Color = model.Color,
GMapPartRecord = partRecord
});
其中 _repository 是 IRepository。 我的代码很久以前就可以工作,现在出现异常 我的列 id 是 migration.cs:
中的标识SchemaBuilder.CreateTable("GMapZonePartRecord",
table => table
.Column<int>("Id", col => col.PrimaryKey().Identity())
.Column<string>("Name")
.Column<string>("Description")
.Column<string>("Color")
.Column<int>("GMapPartRecord_Id"));
错误详情如下:
null id in JooWeb.GMap.Models.GMapZonePartRecord entry(发生异常后不刷新Session)
问题描述:当前网络请求执行过程中出现未处理的异常。检查堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:NHibernate.AssertionFailure:JooWeb.GMap.Models.GMapZonePartRecord条目中的空id(发生异常后不刷新会话)
来源错误:
第 159 行:} 第 160 行: 第 161 行:return 条件 第 162 行:.List() 第 163 行:.Select(x => ContentManager.Get(x.ContentItemRecord.Id, _versionOptions != null && _versionOptions.IsDraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id) ))
源文件:c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs 行:161
堆栈跟踪:
[AssertionFailure: null id in JooWeb.GMap.Models.GMapZonePartRecord entry (don't flush the Session after an exception occurs)]
NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId(Object obj, IEntityPersister persister, Object id, EntityMode entityMode) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:111
NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues(Object entity, EntityEntry entry, EntityMode entityMode, Boolean mightBeDirty, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:81
NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:36
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:161
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:60
NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:30
NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:1182
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:1959
NHibernate.Impl.CriteriaImpl.List(IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:265
NHibernate.Impl.CriteriaImpl.List() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:276
Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs:161
Orchard.ContentManagement.ContentQuery`1.Orchard.ContentManagement.IContentQuery<T>.List() in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\ContentManagement\DefaultContentQuery.cs:262
Orchard.Widgets.Filters.WidgetFilter.OnResultExecuting(ResultExecutingContext filterContext) +4348
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +193
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in c:\Users\JLA\Google Drive\Jooweb\Projects\Orchard.Source.1.7\src\Orchard\Mvc\Routes\ShellRoute.cs:159
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9676252
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
谢谢大家的帮助,我真的不知道去哪里找。
编辑: 添加Nhibernate 3.3.X源后,发现检查失败的不是ContentItemRecord的空值。 有什么想法吗?
你永远不应该使用 Repository<TRecord>
来创建零件记录(你几乎不应该使用 Repository<TRecord>
,句点)。使用您的代码,您创建了与内容项不对应的孤立部分记录。相反,请使用 ContentManager
上的 API,它会负责为您创建所有关联记录。
为了调试,我从 https://github.com/nhibernate/nhibernate-core/tree/3.3.x 下载了 NHibernate 源代码 并发现空值不是像错误消息那样的 id 让我们思考而是 ContentItemRecord.
所以我只是在上面添加了新的值:
_repository.Create(new GMapZonePartRecord
{
Name = model.Name,
Description = model.Description,
Commune = model.Commune,
Quarter = model.Quarter,
Price = model.Price,
StartZoom = model.StartZoom,
StopZoom = model.StopZoom,
Color = model.Color,
GMapPartRecord = partRecord,
ContentItemRecord = new ContentItemRecord()
});
现在一切正常:)