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
|
My Model has an Entity called User and another called AccClaim. AccClaim has a property CaseManager of type user. I am running into problems when I try to change the Case manager on a claim. claim.IsValid is false and I get the error "Case Manager is invalid". When I look at the validation error on claim.CaseManager.AccClaim[0], I get the error "Case Manager is invalid". Eventually, with only a slight cost to my sanity, I tracked it down to claim.CaseManager.AccClaim[26] which was invalid due to some additional OnValidate() code I have just added in. I have resolved this for now by disabling my extra validation if entity state is default, and by cancelling validation on my user if entity state is default. This works for now. This leaves me with a few questions:
Sean |
|
|
For example, there might be custom validation logic that might make it invalid even without any changes to the persistent state, e.g. a maximum number of claims -- adding a claim to the claims collection could make the user invalid without taking it out of the Default state.
We don't load associations just in order to validate them; we just validate the ones that are already loaded. The claims are being loaded from the database when your code references the AccClaims collection (when you call
Generally that should be fine, though obviously you need to be conscious of the considerations in the first paragraph above. If you know that these won't be issues (as they usually won't be) then it's probably safe.
Your best bet is probably to avoid loading the user at all, for example by setting |
|
|
Thanks. That clarifies some things. However it is not working quite the way you way it should.
I'm not touching the AccClaims colection, I am setting the claim.CaseManagerId. I do load the user though, to get the user name for logging and I have the claim.CaseManager set as Eager loading. I am not sure why the AccClaims collection is being loaded, it's not eager loading. In AccClaim:
Any ideas on why it's loading AccClaims? |
|
|
Not sure offhand, though there are some cases where we can end up unnecessarily loading a collection as part of trying to wire up associations (basically to avoid problems with collections that should have changed being materialised unmodified). I thought using the foreign key instead of the entity would avoid this, but I may be wrong. To track down what's causing the load, you can (ab)use the logging infrastructure to intercept all database queries: create a custom logger (http://www.mindscapehq.com/documentation/lightspeed/Testing-and-Debugging/Logging), slap a breakpoint in the LogSql method, and when you see you're breaking on the AccClaim SELECT, take a look at the stack trace. |
|