Working with Multiple Data Access Objects

mmBusinessObject is set up to handle relationships with multiple data access objects. This allows a single business object to read/write data to different types of database, such as SQL Server and Oracle.

Although there is a single DataAccessObject property on your application-level business objects, behind the scenes, mmBusinessObject has a DataAccessCollection property that allows the business object to reference multiple data access classes.

The following methods allow you to work with the Data Access Object collection.

Note that these methods assume a single data access class for each database key! If you want to use multiple data access objects for a single database key, see the next section below.

Method Description
GetDataAccessObject Returns an instance of a data access object for the specified database key. If a data access object isn't found, a new one is created
GetExistingDataAccessObjectByDbKey Returns a reference to an exising data access object that has the specified key
GetExistingDataAccessObjectByClass Returns a reference to an existing data access object that is of the specified class
SetDataAccessObject This method allows you to manually specify data access settings, and creates a data access object based on these settings. If you specify a null DataAccessClass, this method assumes a SQL Server data access class
SetDataAccessObject This method allows you to manually specify a data access object

Using Multiple Data Access Objects for a Single Database Key

If you want to use multiple data access objects for a single database key, you can override your business object's GetDataAccessObject() method like this:

public override mmDataAccessBase GetDataAccessObject(string databaseKey)
{
	if (someCondition)
	{
		return this.DataAccessObject;
	}
	else
	{
		return this.DataAccessObject1;
	}
}

The DataAccessObject property already exists on your business object (if you have generated a data access class using the Business Layer Generator) and returns a data access class of a specfic type. You can create another property (e.g. DataAccessObject1) that also has lazy instantiation (see the code in the DataAccessObject property for details). In your override of GetDataAccessObject() you can check some condition to see which data access object to return.


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/28/18
Comment or report problem with topic