NHibernate - Lazy Loaded Collection -


Will a lazy loaded collection in NHibernate ever give me a NullReferenceException? I get an exception in one of the following ways:

  Public Zero Test (Asynation session, int id) {var entity = session.Load & lt; MyEntity & gt; (Id); Entity.LazyLoadedCollection.Add (SomeItem); }  

Calling LazyLoaded to call is throwing. My mapping looks like this:

  & lt; Bag lazy = "true" table = "mytable" & gt; & Lt; Key & gt; & Lt; Column name = "Lazy Loaded Collection" /> & Lt; / Key & gt; & Lt; Many-to-many classes = "LazyLoadedItem" & gt; & Lt; Column name = "LazyLoadedItemId" /> & Lt; / Many-to-many & gt; & Lt; / Bag & gt;  

Is it the expected behavior in NHibernate?

It's hard to say without looking at your class, but one thing you do not feel That is, you have to populate each collection in your class constructor.

NHibernate will replace these collections with their own at some time, but you still need to make sure that they initially have a HashedSet & lt; T & gt; , list T & gt; , or something else that you are using, are population based on them.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -