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 think this has come up before and the asnwer was that it wasn't really possible at the time, but I want to raise the issue again and see if anthing happened....
What I want to be able to do is tell a UoW to repopulate some entities from the database. For example, each winform has it's own unit of work and form A shows a list of entities and a button to open form B (to add/remove/alter the entities). Because form B has it's own UoW it gets a fresh copy of the entities from the DB for editing, however when form B calls SaveChanges(), closes, and focus returns to form A there dosen't seem to be an easy way to repopulate the list of entities. I don't want to call saveChanges(reset) on form A because there may be outstanding changes that shouldn't yet be commited, and using form A's UoW.Find method only returns the existing (now out of sync) entities. This is the only way I can think of to update the existing entities on the parent form once they have already been loaded: formB f = new FormB();
Am I making this way harder than it needs to be? I just want to force an entity or a collection of entities to repopulate their properties from the DB. |
|
|
It is not currently possible to reload entity data; you must load the entities into a fresh unit of work to get the changed values, as per your example code. However, one possible simplification to your code is that, instead of copying the data, you could use the Attach method to move the entity from the fresh unit of work into the "work in progress" one. In this case, though, you are dealing with a different object instance and will need to update Form A's list of entities to point to the new instances. You might also want to check out JD's post Tips for rich client development. |
|
|
thanks Ivan.
Question; What happens if a UoW has already loaded MyObject with Id 99, then I create a separate UoW, fetch that same MyObject by Id, make changes, and then attach it to the first UoW? exception? conflict resolution?
For what I'm doing now I will have to stick with the property-copying method as in my example as the entities that are being updated have some large child collections that are loaded in the first form and it would be rather expensive to load them all again just to change a property on the parent. A "ReloadEntityProperties" method would be really useful... |
|
|
I believe the existing #99 will be automatically unregistered, and will effectively be replaced with the new #99. I would advise testing this scenario though. You may also need to do some testing around the handling of associations depending on what associations your objects have, when they are loaded and how they are used on the form that you're coming back to -- specifically e.g. objects that had a loaded reference to the old #99 will still have that reference to the old #99. We do not do any conflict resolution. This is up to applications to handle. We hear you on the "refresh" method and we know there are a lot of people asking for this. |
|