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
|
Hello, Lately I've been using Lightspeed but this week I ran into a problem. My goal is to read the PerformedAnalysis-model with its references to other models. The data is getting read perfect but whenever accessing the one-to-many reference I got an "ObjectDisposedException". Reading data:
Error:
Accessing data inside XAML with data-binding:
Property:
Whenever I remove the using-statement everything goes fine. Any suggestions? Thanks! |
|
|
Hi, I think the issue is because of this line:
If I'm following it correctly, you do a .ToList() so that you fetch everything from the database that you need in the view.. The UnitOfWork then gets disposed of at the end of the using block however, in your binding, you're trying to walk the association Analysis.Name. I'm picking you have not eager loaded Analysis for each PerformedAnalysis and therefore when LightSpeed goes to lazy load that object it finds the underlying UnitOfWork is now gone and gives the exception. Could you try:
For a screencast on eager loading and named aggregates click here. I hope that makes sense! John-Daniel |
|
|
Yes, you are following it correctly. The situation you outlined was the same as I had in mind, but clueless in solutions. Setting "Eager Load Backreference" to "True" works like a charm. Thanks for the quick and complete answer! |
|
|
I'm running into something unexpected, therefore I'd like to ask you another time for help. The application is running smooth but my unit tests aren't. Code below performs an update test on the PerformedAnalysis entity:
In its simplest form it creates a new PerformedAnalysis with default data, updates several properties and lastly the AreEqual-method is getting performed. The error occurs on this line: "performedAnalysis.User = user;":
I've set "Eager Load Backreference" to True but still getting an error. Thanks for the help :-) |
|
|
It looks like something is disposing the unit of work, but it's a bit hard to tell when or why (or which, if the repositories are sitting over different UOWs) because the UOW code is encapsulated within the repository classes. (Which isn't a bad thing, it just means we don't know how the repositories are interacting with the LightSpeed bits.) You don't say whether all your tests are failing or just this one. If it's all your tests then I'd guess that your test setup method (in MSTest I think this with TestInitializeAttribute) is inadvertently disposing the UOW, perhaps assuming a different lifecycle from the app code that works. Another possibility is mismatched creation and disposal e.g. you create the repositories in ClassInitialize but dispose them in TestCleanup (so they are disposed after the first test but not recreated before the second test). A diagnostic suggestion would be to temporarily override the Dispose method on your UOW class, so you can set a breakpoint and examine the stack trace to find out what is disposing it and when, e.g.
Once you have the stack trace it will hopefully be obvious where things have gone wrong! |
|
|
Thanks for the quick reply Ivan, unfortunately your response doesn't help me resolving the described problem. To clarify matters I'll post my RepositoryBase-class:
The _context-property is a static property inside the DatabaseConfigurationBase-class. The RepositoryBase As an answer on your post the UOW will get disposed after every database action, is this the intention, or? Therefore the stack trace didn't gave any helpful information (since I know when it is getting disposed). For further notice; it was only this test that failed. Though I ran into another problem in the application itself. Via a columnbox a reference property is getting changed and at this point I'm getting the same error. Your help is appreciated, thanks! |
|
|
Your problem is that you are disposing the unit of work after every action, rather than when your work is done. For example, you pass the The way you need to work is to create a single unit of work per 'scope' -- per Web page, per WPF window, per test, etc. -- and do all your work within that unit of work. Your current repository treats a unit of work as a single database command; it's better to think of a UOW as a business-meaningful chunk of work, a session, which may comprise several database loads and saves. This will also address your column box error. Keep your unit of work around for the duration of the interaction, do all LightSpeed actions involved in the request through the same UOW, and dispose the UOW when closing the form. (There are some subtleties around long-lived forms where you may need to identify finer UOW boundaries.) See Unit of Work Scoping in Building WPF and Windows Forms Applications in the LightSpeed user guide for more info: http://www.mindscapehq.com/documentation/lightspeed/Building-WPF-and-Windows-Forms-Applications- Hope this helps! |
|