R – ORM with good support for long running context

netorm

Related question here.

With most ORMs when you run a query against an existing context it does not return data that has been changed since the objects were first returned from the database. It issues the query to the DB but any changes made to the DB aren't returned because the context doesn't want to stomp on your objects (for a discussion of this behaviour in Linq to SQL see here). This is fine for short lived contexts using the Unit of Work pattern but not so good if you are using long lived contexts.

I have tried Linq to SQL and Entity Framework, both frameworks provide a refresh method that lets you specify an enum argument to overwrite existing object in the context, but this will not pick up new records (at least not without an additional query) and more importantly will not remove objects for records that have been deleted from the DB.

I know I can just discard the context and the existing objects but I don't want to do this because the objects are bound to other elements in the application.

Is there any ORM that has the ability to refresh the objects with the latest data for the DB, adding objects for newly created objects and removing objects for records that have been deleted from the DB, ideally in an efficient way (i.e. using MS SQL rowversion columns).

Best Answer

I am not sure, but it seems you need something similar to DataObjects.Net behavior. Their entities are long-living session-bound objects that store data in transactional state. When you open new transaction and read persistent property of existing objects, they automatically fetch it from database (it also concerns EntitySet properties).

Of course you should execute complex queries for each transaction to keep query results in actual state, but i think it can be easily automated.

Related Topic