简体   繁体   English

NHibernate Evict抛出未设置为对象错误实例的对象引用

[英]NHibernate Evict throws an Object reference not set to an instance of an object error

When I: 当我:

if (nhsession.Contains(myobj))
    nhsesion.Evict(myobj)

At the Evict method call I get this error: Evict方法调用中,出现此错误:

{"Object reference not set to an instance of an object."}     ????????

With this stacktrace: 使用此堆栈跟踪:

at NHibernate.Event.Default.EvictVisitor.EvictCollection(IPersistentCollection collection)
   at NHibernate.Event.Default.EvictVisitor.EvictCollection(Object value, CollectionType type)
   at NHibernate.Event.Default.EvictVisitor.ProcessCollection(Object collection, CollectionType type)
   at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Object value, IType type)
   at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Int32 i, Object[] values, IType[] types)
   at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types)
   at NHibernate.Event.Default.AbstractVisitor.Process(Object obj, IEntityPersister persister)
   at NHibernate.Event.Default.DefaultEvictEventListener.DoEvict(Object obj, EntityKey key, IEntityPersister persister, IEventSource session)
   at NHibernate.Event.Default.DefaultEvictEventListener.OnEvict(EvictEvent event)
   at NHibernate.Impl.SessionImpl.FireEvict(EvictEvent evictEvent)
   at NHibernate.Impl.SessionImpl.Evict(Object obj)
   at NewCash.UI.Presenters.OperazioneIRSPresenter.UserAction(String Action) in C:\AkrosProduzione\NewCash4\src_4\NewCash.UI\Presenters\OperazionePresenter\OperazioneIRSPresenter.vb:line 230

It seems that NHibernate evict tries to evict a null collection, how can I avoid this without having to initialize all collections properties of the object? 似乎NHibernate evict试图逐出一个null集合,如何避免这种情况而不必初始化该对象的所有集合属性? Or is there a problem that I'm misunderstanding? 还是我误会了一个问题?

it looks like a bug as Rippo linked. Rippo链接时,它看起来像是个错误。

however even if it is a bug it is good practice to initialize collection properties to empty collections in the constructor of the model classes. 但是,即使这是一个错误,在模型类的构造函数中将集合属性初始化为空集合也是一个好习惯。 Then it is not nessessary to check for null collection each time on access and to change the collection type (eg decorating it) there is only one place to change it. 这样就不必在每次访问时检查空集合并更改集合类型(例如,装饰它),只有一个地方可以更改它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NHibernate,对象引用(配置)未设置为对象的实例 - NHibernate, Object reference(configuration) not set to an instance of an object FirstOrDefault()抛出未设置为对象实例错误的对象引用 - FirstOrDefault() throws Object reference not set to an instance of an object error 图片框始终抛出未设置为对象错误实例的对象引用 - Picture box always throws object reference not set to instance of object error 编辑抛出错误:对象引用未设置为对象的实例 - Editing throws error : Object Reference not set to an instance of an object Telerik Radgrid rebind()抛出未将对象引用设置为对象错误的实例 - Telerik radgrid rebind() throws Object reference not set to instance of object error 对象引用未设置为实例错误 - Object reference not set to an instance error 错误:对象引用未设置为对象实例错误 - Error : Object Reference not set to an instance of an object error ManualResetEvent.WaitOne()抛出NullReferenceException:对象引用未设置为对象的实例 - ManualResetEvent.WaitOne() throws NullReferenceException: Object reference not set to an instance of an object GetOriginalTypeParameterType throws未将对象引用设置为对象异常的实例 - GetOriginalTypeParameterType throws Object reference not set to an instance of an object exception DocumentElement.AppendChild抛出未设置为对象实例的对象引用 - DocumentElement.AppendChild throws object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM