我使用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。 我的代码很久以前就已经开始了,现在我得到了一个例外 我的列标识是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"));
以下是错误的详细信息:
JooWeb.GMap.Models.GMapZonePartRecord条目中的null id(发生异常后不要刷新会话)
描述:Une例外非géréess'estproduite au moment de l'exécutiondelarequêteWebactuelle。 Contrôlezlatrace de la pile pour plus d'informations sur l'erreur et son origin dans le code。
Détailsdel'exception:NHibernate.AssertionFailure:JooWeb.GMap.Models.GMapZonePartRecord条目中的null id(在发生异常后不要刷新会话)
Erreur来源:
Ligne 159:} Ligne 160: Ligne 161:退货标准 Ligne 162:.List() Ligne 163:.Select(x =&gt; ContentManager.Get(x.ContentItemRecord.Id,_versionOptions!= null&amp;&amp; _versionOptions.IsDraftRequired?_versionOptions:VersionOptions.VersionRecord(x.Id)))
Fichier来源:c:\ Users \ JLA \ Google Drive \ Jooweb \ Projects \ Orchard.Source.1.7 \ src \ Orchard \ ContentManagement \ DefaultContentQuery.cs Ligne:161
Trace de la pile:
[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的空值。 有什么想法吗?
答案 0 :(得分:2)
您永远不应该使用Repository<TRecord>
来创建部分记录(并且您几乎不应该使用Repository<TRecord>
,句号)。使用您的代码,您创建了与内容项不对应的孤立部件记录。相反,使用ContentManager
上的API,它将负责为您创建所有相关记录。
答案 1 :(得分:0)
要调试我从https://github.com/nhibernate/nhibernate-core/tree/3.3.x下载NHibernate源代码 并发现null值不是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()
});
现在一切正常:)