tprohas wrote:
I'm trying the save entities and then use the entities values to set the values in some other entities and I keep getting this error stating that the in-memory entities are out of sync with the database. I just want to be able to use the entities values to do some calculations.
Does anyone know if its possible to use the values from a saved entity without having to refetch it. Should I do the calculations before saving the entity that is causing the error?
It's best to refetch an entity after the save, as your save might insert default values for fields you haven't specified a value for, which are then loaded into the entity in memory.
You can of course fake it and set entity.Fields.State to EntityState.Fetched, but that's not recommended.
The other problem that I see here is that if I want to have computed db columns where I do something like the following I have to refetch the data. This refetch adds quite a bit of load on the database which I don't like.
ALTER TABLE TableName
ADD TotalSalePrice AS UnitSalePrice * Quantity
I think because the value is being changed on the database side then the entity would have to be refetched to get the new value. This makes sense to me, the first example of the problem doesn't since I expect I should be able to get access to the values of the entity even though the entity has been saved.
computed columns are also a reason to refetch an entity after a save IF you want to use the values in the entity after teh save. You can also reschedule the save till after the actions on the values.