[英]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.