This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am populating a gridview with a list of objects just for display purposes, so am disposing of the uow after the table is bound. The objects that I am retrieving have a child object which is set to eager load. using(IUnitOfWork uow = Context.CreateUnitOfWork())
this is fine and the table populates ok, but if I try to access the child object later I get a disposed object exception because it's outside the using block and it's been disposed. The problem is that during databinding the child object is definitely loaded, but inaccessible after the uow is disposed.
I suppose my question is this: does the EntityHolder throw an exception if the uow is disposed, even if the child is loaded, and if so, then is the only solution to keep the uow alive as long as the form exists? |
|
|
sorry, should've said datagridview - this is winforms |
|
|
EntityHolder will throw if it needs to load the object after the UOW has been disposed. It should not throw if the object is already loaded and wired up when you traverse the association. It sounds like either the associated object is not being eager loaded as you believe it is, or something is being changed that makes LightSpeed think it needs to reload (e.g. something in the entity graph has been attached to a different unit of work, or a foreign key has been changed that means the EntityHolder needs to load a new value). (Note that the associated entity merely being loaded into the UOW is not sufficient. If you do a Find<Parent>() and Find<Child>(), where Parent.Child is NOT eager-loaded, then all the children are loaded, but the Parent.Child associations are not yet wired up, and don't get wired up until the association is traversed. And wiring up requires that the UOW be "live.") You can check whether the associated object has been wired up examining EntityHolder.IsLazy -- this will be false if the associated entity has been loaded and wired up to the EntityHolder. |
|
|
Thanks Ivan, I will have to check it out some more if I have time... I can tell you though that the child object is definitely loaded, as during the initial databinding the parents child is used to populate a cell.
I suspect your second option around something in the entity graph having changed, causing LS to want to reload the child is probably what's happening here.
thanks again |
|