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
|
Not sure where this might be documented but im trying to read a member of an Entity object which is a relationship/EntityCollection to another Entity object within the AfterLoad override of the parent object and i get an exception of: There is already an open DataReader associated with this Connection which must be closed first. Im using MySQL. Any ideas why I cant access these types of members within some of the overrides? (it also happens in OnEntityStateChanged)
Alfred |
|
|
This occurs because AfterLoad is called immediately the entity has been materialised from the database. The DataReader which we are using to load objects has not yet been closed, because there might be more objects still to load (e.g. if the Find is returning multiple results, or there's an eager load happening). If your AfterLoad code accesses another entity which has not yet been loaded, that will trigger a database access in order to load that second entity, which will fail because the connection is still busy with the original database access. The upshot is that you will not be able to reliably traverse associations in AfterLoad. The same situation will apply in OnEntityStateChanged when the state change is from New to Default, because LightSpeed sets the state of a loaded entity to Default immediately the entity has been materialised (in fact, just before calling AfterLoad). So again the data reader is still open at this point. Could you say a little more about what you're trying to achieve in your AfterLoad code? We may be able to suggest an alternative approach that wouldn't run up against this problem. |
|
|
Thank you for this quick reply on a day where most ppl are gone for the holidays :) im trying to save information before some values get modified, this includes finding a particular child object who has the particualr value (lowest date in this case). This is used to move some files based on the value of this object, so need to track the from/to pair when the object is saved back. Its a bit late in development cycle to re-schema the DB without getting in to trouble :) |
|
|
This isn't elegant, but as a workaround, since it sounds like you need to save the information only if values get modified, you could override OnPropertyChanged (remember to call the base class implementation if you do this!). This will get called only by user changes, after the entities have been loaded, so should be able to safely access associations that might trigger a database access. The downside is that OnPropertyChanged is called only *after* a property has been changed. So you would not have access to the original value of the changed property. Whether this is an issue depends on whether the "child with lowest date" could potentially be affected by a value change. Is that any use to you? Another possibility is simply to add an explicit method on the specific entity class and call it on each resulting entity after calling Find. However this will not work if the entity is loaded implicitly via an association. |
|