NHibernate缺少SqlParameter for overriden属性

时间:2012-11-26 16:59:10

标签: nhibernate fluent-nhibernate automapping table-per-hierarchy

我正在尝试使用FluentNHibernate AutoMapping实现table-per-hierarchy方法 我有一个基类和三个子类。第三个子类重写了基类的几个属性。前两个子类的实例保存得很好,但当我尝试使用重写属性保存第三个类的实例时,我得到了

Invalid index 7 for this SqlParameterCollection with Count=7.

似乎NHibernate没有为重写的属性添加SqlParamaters,但它试图设置一个值。

如何解决这个问题?也许映射/配置有些变化?

StackTrace:

[IndexOutOfRangeException: Invalid index 7 for this SqlParameterCollection with Count=7.]
   System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32 index) +5033831
   System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32 index) +21
   System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index) +10
   NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value, Int32 index) +74
   NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index) +70
   NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session) +37
   NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index) +189
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +498
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) +166
   NHibernate.Action.EntityInsertAction.Execute() +181
   NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +42
   NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +59
   NHibernate.Engine.ActionQueue.ExecuteActions() +16
   NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +121
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +92
   NHibernate.Impl.SessionImpl.Flush() +291
   MDT.Core.DataAccess.DbContext.Flush() in C:\dev\DHL\ISS\Common\MDT.Core\DataAccess\DbContext.cs:215
   ISS.Web.Controllers.ReportScheduleController.Index() in C:\dev\DHL\ISS\ISS.Web\Controllers\ReportScheduleController.cs:55
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

1 个答案:

答案 0 :(得分:0)

是的,FluentNHibernate AutoMapping为重写的属性添加重复映射 奇怪的是,代码没有帮助

.Override<ThirdClass>(map => { map.IgnoreProperty(p => p.Age); }) 

所以我必须使用

.OverrideAll(map => map.IgnoreProperties(x => x.MemberInfo.HasAttribute<IgnoreMapAttribute>()))

并在我的班级中设置[IgnoreMap]属性。