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
|
Hi,We were looking for an O/R mapping framework to use in our new project and where about to choose NHibernate till we found LightSpeed. For single entities it works great!, but when we did a simple master/detail test the details didn't change when the master was switched to another record.
We found only one post about this issue, so we think we are missing something simple here but we didn't find out yet. You can download the sample here: http://rj.tempro.com.br/Samples/TelephoneAgenda.zip (it's on Visual Studio 2008, LightSpeed2 and the script for DB sql server 2005, also included in zip file) In the load event you will find this:using (TelphoneAgendaUnitOfWork uow = Repository.Context.CreateUnitOfWork()){ contactBindingSource.DataSource = uow.Contacts; }In the form the contacts and telephone list are loaded immediately, but when we navigate through the contacts, the telephone list grid detail doesn't change.We will really appreciate some help here.
|
|
|
Hi Juan, Thanks for the comprehensive and detailed repro case. The problem is related to the lazy loading of the Telephones association. If you look in the Visual Studio Output window when you navigate between Contacts you will see a message reporting an ObjectDisposedException. This is because the unit of work containing the Contacts has been disposed, and is therefore no longer usable for fetching the associated Telephones. There are two possible solutions: 1. Keep the unit of work around for longer. For example, make it a member variable of the form, and dispose it when the form closes. This is a nice simple solution for this sample app, but requires caution when scaling up to a more realistic app -- if you keep the unit of work around for *too* long then the risk increases of the client-side data getting out of sync with the database (assuming other people may be modifying the database at the same time.) So you will need to think carefully about what is the appropriate lifetime for a UOW. 2. Mark the Telephones association as eager loaded (select the arrow and set Eager Load Collection to True). This tells LightSpeed to load a Contact's Telephones at the same time as loading the Contact. This means the Telephones get loaded while the unit of work is still alive. (LightSpeed does this efficiently in a single query.) Again, this will work nicely for your sample, but if Telephone were a large data structure or each Contact had a lot of Telephones, it could make loading a large data set a bit costly. Also you would need to create a new UOW and attach things to it in order to save them. My recommendation in this case would be option 1, because it makes the SaveChanges scenario a lot easier when you come to trying out that side of things; but as noted care is required around the appropriate lifetime for a "longer-lived" UOW. |
|