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'm using reflection to loop through multiple levels in an object hierarchy, and update their values. All goed well but the EntityState does (naturally) not get updated. I can also NOT manually set this value to Modified from Default, how can I use reflection, and automatically set the attribute?
eg: where the source, and dest are Mindscape data classes . Lib.Reflection.CopyValues(source, dest);
Anthony |
|
|
Is your Reflection code updating values by setting properties or fields? Setting properties should update the EntityState, even if the property setter is called using Reflection. Of course, this will update the entity to Modified. There isn't a mechanism for resetting an entity from Modified to Default other than saving it -- at least, not that's intended for production use. Could you clarify why you want to change the entity state from Modified to Default without saving it? |
|
|
I'm using the following code: public static void CopyValues<T>(T source, T destination) I load an entity from the Database (including all 15 child related objecst in a tree hierarchy). I then create a new entity performing various calculations. (largely the same as the original entity from the Database) I then walk through the Database version, and my new class, and depending on certain criteria, optionally update the database entity. I then save the Original entity back to the Database. I hope this clarifies my problem. Anthony |
|
|
Change the CopyValues implementation to loop over properties instead of fields. In this way your changes will go through the property setters, which call Entity.Set, and this will cause LightSpeed to change the entity state to "Modified." (This is also important if one of the values that changes is a foreign key, though it sounds like that probably isn't the case in your scenario.) Some caution may be required around updating properties of entity type (many-to-one associations). You alluded in an earlier post to wanting to change a Modified entity back to Default, but I'm not sure where this fits into the account above. The original entity should change from Modified to Default when you save it, and it sounds like the new instance is transient so its state doesn't matter. Or am I still missing something? |
|
|
Hi guys, I want to give an option to user to force the Save for second time after inspecting merged values and error information, but a recall to Save will do nothing as Entity is in "Default" state (in situations where only IDataErrorInfor errors were updated within the Entity). |
|