concept persistence - relate code in category .net

appears as: persistence-related code, persistence-related code
NHibernate in Action

This is an excerpt from Manning's book NHibernate in Action.

By this definition of transparent persistence, certain non-automated persistence layers are transparent (for example, the DAO pattern) because they decouple the persistence-related code with abstract programming interfaces. Only plain .NET classes without dependencies are exposed to the business logic. Conversely, some automated persistence layers (like many ORM solutions) are non-transparent, because they require special interfaces or intrusive programming models.

Now let’s see how you can implement an entity that is as free as possible of persistence-related code while still being functional and simple.

9.3.1. Abstracting persistence-related code

A common compromise, at the level of persistence awareness, is to separate persistence-related code from the business code in the implementation of an entity. This can be as trivial as performing a visual separation using a #region in your code, to help improve readability. Another option is to create an abstract base class for each entity so that persistent code is separated.

You’ll implement an abstract class from which entities can inherit to gain the persistence-related code they need. This class will provide an identifier and a version property along with proper overloading of System.Object methods. You’ll call this class VersionedEntity; listing 9.2 shows its implementation.

Listing 9.2. VersionedEntity base class abstracting persistence-related code