Is it possible to adopt the use of an O/RM like NHibernate or Entity Framework, and abstract it in such a way that it could be replaced if a situation is encountered that the O/RM cannot handle.
It seems tempting to create a service with chunky service methods inside of which, a session is created, the session is used to get / upsert entities and is then used to save all dirty objects.
I would have considered the repository pattern so that the service operation asks the repository for entities, and the O/RM session is embedded in the repository. But what do you do about saving related entities, and does an Update(T entity) method flush changes imediately. It seems to simple and generally unsatisfactory.
What I am leaning toward now is a single O/RM wrapper class that exposes an interface with generic methods like "StartSession", "EndSession", "AbandonSession", "GetById(object id)" etc.
At least this would allow the OR/M to be faked in testing which is another big concern of mine.
I guess I'm saying that I don't want to closely intertwine business logic, and O/RM data access code, because switching to another O/RM could cause most of that code to be replaced.
What do people do in the real world?