The protected field that is null (orderDates) is accessed via a public virtual property getter. This property is read-only (no setter). The field (orderDates) is not referenced directly in this property getter but a few private methods down.
Incidentally, the error appears only after the same code path is called many times (in a loop) without error. The error appears on a particular instance of an entity (Order). I feel certain that the entity (Order) has all of it's public members as virtual (it's proxy-able) because it is mapped as lazy=true. On Apr 7, 4:26 pm, Fabio Maulo <[email protected]> wrote: > Is not a matter of initialization but a matter of access. > probably you are trying to access to the field from a no virtual property > and the instance you are using is a proxy. > > > > > > > > On Thursday, April 5, 2012 6:29:25 PM UTC-3, Tim Scott wrote: > > > After upgrading to NH 3.2.0.4000 we now get an exception here because > > orderDates is null. > > > foreach (var orderDate in orderDates) > > > It's declared thusly: > > > protected IList<OrderDate> orderDates = new List<OrderDate>(); > > > And mapped like this: > > > <bag name="orderDates" access="field.camelcase" inverse="true" > > lazy="true" cascade="all-delete-orphan" > > > <key column="OrderId" /> > > <one-to-many class="OrderDate" /> > > </bag> > > > A few frames down in the stack trace is: > > > at NHibernate.Proxy.DefaultLazyInitializer.Intercept(InvocationInfo > > info) > > > There are no matching order date rows in the database. > > > Why is NH lazy initializing this collection to null instead of > > empty? How can I fix? -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
