Object context, proxy-based change tracking and entity data consistency

Dec 24, 2012 at 6:00 PM


I'm not sure it's an RO-related issue, but I'm experiencing it in the context of RO:

One of my domain classes contains a numeric property which is updated very frequently.  For this reason, this property is not persisted to the database using the framework:

public virtual int CurrentSessions
    get { return _currentSessions; }
    set { Interlocked.Exchange(ref _currentSessions, value); }

The issue I'm facing is that the value of the property is not updated across sessions.  The service invoked from the RO API controller either increases the above value or decreases it via a proxy object.

When I inspect the value of myObj.CurrentSessions after it has been increased/decreased, it is indeed updated, but on the next server request, when myObj is retreived again, CurrentSessions has always its initial value, zero.

How can I make sure the property value is updated in the POCO entity?

Dec 28, 2012 at 10:35 AM

Restful Objects for .NET is a 'stateless' architecture  -  every request retrieves the needed objects afresh from the persistent object store.  Apart from the fact that this is the architecture of the underlying Naked Objects framework, it is also a fundamental principle of REST.  It follows that if an object holds data which is (deliberately) not persisted, then this will always be lost between requests.

If the doctrinal principles of REST are not important to you (though you should be careful as there are great benefits from adopting them) then you could choose to store those values on the Session.  

Dec 30, 2012 at 8:00 PM

Thanks Richard.

I think I got your point and realized I'm actually looking for a "backdoor" into the persistence layer, which doesn't exist.

I ended up using a thread-safe dictionary for my counters.  I'm persisting it directly to non-modeled tables in the database, and while it's less elegant than properties, a little more coding implements the required functionality.