Working Together: IDbDataContext and DbRepositoryBase

ADO.Net provides the basic data access capabilities of .Net. Even with the Entity Framework around, ADO.Net remains solid. Just like how the very basic concept of the typewriter remains alive in our keyboards, ADO.Net is here to stay. Mendz.Data.Common embraces this assumption as fact, in order to provide the APIs needed for creating contexts and repositories.

The Entity Framework, as do most ORMs, introduce the concept of "contexts" to manage database connections and transactions. This language per se is not compatible with ADO.Net, which has distinct representations for connections and transactions. Mendz.Data.Common's IDbDataContext and IDbDataTransaction interfaces make it possible to make ADO.Net's "language" to be more compatible with the concept of "contexts".

IDbDataContext is implemented by Mendz.Data.Common.GenericDbDataContextBase, which is derived by Mendz.Data.Common.DbDataContextBase, which also implements IDbDataTransaction. Classes that derive from DbDataContextBase centralizes the management of ADO.Net connections and transactions, thus making them "context" compatible.

Making ADO.Net "context" compatible made designing Mendz.Data.Common.DbRepositoryBase possible. DbRepositoryBase supports creating repositories using the "context" concept to manage connections and transactions. Thus, for example, DbRepositoryBase can be used to create repositories with Entity Framework's DbContext, Mendz.Data.SqlServer.SqlServerDbDataContext and Mendz.Data.MongoDB.MongoDbDataContext.

Speaking of Mendz.Data.MongoDB, note that the MongoDB .Net driver is not ADO.Net compatible. However, GenericDbDataContextBase allowed for it to be wrapped in to MongoDbDataContext, a "context" compatible instance. This solution makes it possible to use MongoDB in repositories based on DbRepositoryBase.

DbRepositoryBase supports the "context" concept. IDbDataContext provides the solution to making non-context-based database access clients/drivers to be wrapped in to "context" compatible instances. The solution makes DbRepositoryBase a powerful API for creating repositories with consistent features and quality. Use Mendz.Data to establish a consistent "process" for yourself and for your team when creating repositories.

Comments