I use a homemade DataAccess layer and it looks like this:
public class HoneyOpposumDAO : DataAccessObject<lots of generics> { public ICollection<HoneyOpposum> Select(Filter filter); public ICollection<HoneyOpposum> Select(); public HoneyOpposum FindByApplicationId(int id); internal HoneyOpposum FindByDatabaseId(int id); void Register(HoneyOpposum o); void Commit(HoneyOpposum o); void CancelEdit(HoneyOpposum o); void Save(); void Save(Filter filter); void Save(DbTransaction transaction, Filter filter); void Revert(); void Revert(Filter filter); void Revert(DbTransaction transaction, Filter filter); }
Filters are composite structures to express Filter Expressions in DataSets.
Basically, this is a three-tier DataAccess layer :
- Business objects (model)
- DataSets
- Saving structure
Business objects have to register themselves using Register. Modification to these objects are confirmed to the model using Commit and can be undone using CancelEdit.
Commited business objects can be saved to the underlying saving structure (e.g. SQL Server) using Save and all changes since the last Save can be undone using Revert.
This DataAccess layer ensures control on saved and unsaved business objects. It also allows for seperate database and application ids.
Unfortunately, the underlying code quite complexe... and copyrighted :)