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
|
Is there a way to refersh an entity? Say I have some objects and I want to make sure I have the Latest copy of them from the Database. Do I just run a query to retrieve that entity from the Database? or will that give me the Cached Copy or is there Something like: unitOfWork.Refresh(MyEntity) or unitOfWork.Refresh(MyEntities) ?? I guess there could be problems if MyEnity has changes and so does the database for that Enitty. your thoughts would be much appreciated |
|
|
Hi Tommy, By design the entity is loaded from the identity map if it has already been loaded within the current unit of work. This is to ensure you get the same entity back across multiple queries which may load it. To flush it, you would need to clear the unit of work (e.g. UnitOfWork.SaveChanges(true) and then load it directly again. We are going to have a chat about what you have suggested as we can see the upside here, although there would be potential consistency issues with this (e.g. should we be refreshing any dependent associations as well?). Out of interest, what is the situation that needs you to refresh the entity, presumably database consistency concerns in a longer running unit of work?
Jeremy |
|
|
I have several scenarios I am pursuing. One would be an app that runs on the local network and all users can see updates to the Database. I can notify users of changes via WCF and thought that a Refresh method for a given entity would be awesome and not post unnecessary changes back to the Database if I were to send the Updates via WCF. (Each local copy would think it had been changed and post updates on SubmitChages when it just needed a refresh) Or even keeping data syncronized if the user has the program opened twice an makes a change it would be visible in both instances. I tend to have longer running unitsofwork. I dont see how to keep them short unless I track what needs to be saved manually. I wouldnt need to refresh Associated entities. But would like to refresh Associations if the association changed. Like if someone moved a "PartA" from parent "DrawingA" to "DrawingB" I would notify the network "PartA" had changed then each client would call a refresh and then see that partA was now on DrawingB and not DrawingA |
|
|
I would like to second this request. There are two types of refresh, refresh on local entity only and the condition that is more complicated which is refreshing all of the related child tables. To me, refresh would be the current entity only for now and maybe in the future, you could use the aggragate feature to tell what other entities may be refreshed. If refresh is no possible, a "IsEntityStale" would be nice. I can give 4-5 different reasons why I need this feature for this one type of entity. Thanks Joe Feser |
|
|
I would like to third this request (if there is such a thing)! A way to expire the 1st level cache (the identity map) without calling SaveChanges is really what would accomplish this for us. |
|
|
Hi guys, Would you expect that if you called a UoW.Refresh(entity) type method that it would throw out all changes you may have made to the entities in that aggregate? Thanks, John-Daniel |
|
|
Most of the time yes, sometimes no. |
|
|
How did I know that would be the case ;-) Adding a method to refresh that refreshed only, rather than offered some form of change reconciliation, would obviously be considerably easier to build and test. I'm not sure what would make an elegant API for reconciling changes when calling the Refresh method, would be something to get your thoughts on. Kind regards, John-Daniel Trask |
|
|
From what I can remember, the entity base keeps track of "original value" but I don't remember if it knows that just one field has changed or if the object is just dirty. This may only be the case in a BeginEdit Condition. I am still rolling back the tape in an attempt to remember. :) At minimum, a refresh would be great, loosing changes because in my case, I would refresh, perform an edit and them commit. The second level would be the prefered, but maybe only in during a BeginEdit condition if that makes it easier. Here is my condition. I load 3-5k records of a type into a collection and I then use that list to call a web service. It may take 15-20 minutes and sometimes an hour to run the entire list. If by some chance, this enitity has changed behind the scenes, I may not consider it a change. Does this help? Joe Feser |
|
|
http://msdn.microsoft.com/en-us/library/ms172088(VS.71).aspx Diffgram is one way. We would like to be able to refresh just *part* of an object graph (a child entity or collection), or *all* of the object graph if possible. |
|