In the previous article, we created our own data access layer (1). We have learned the basic principles of. NET database operations and raised several questions about the use of Ado.net objects:
1. How the system determines the database type.
2. How to eliminate the repeated code.
In the previous article, we also proposed a solution to encapsulate ADO. NET objects. How should we implement them?
1. An object is required. This object is used to establish the ing between the memory table and the physical table, solve data query and update operations, and form a data ing object, which is defined as DataMapping.
2. Each ing object only establishes a ing relationship with one physical object. If multiple such objects operate simultaneously, how can this problem be solved? In this case, another object is required to add a ing object set, package the ing object operation, and form a data executor, which is defined as DataExecutor.
Think about it. You only need these two basic objects to form a simple data access layer.
DataMapping should be implemented first. It should have the following functions.
1. You need to know the information of the physical table, including the table name, primary key set, and field set.
2. You need to know what type of database is mapped, MSSql database, Oracle database, MySql database, or other types of database.
3. You can query the data, that is, fill the memory table.
4. data can be updated and the update operation method can be set.
5. You can join the transaction.
Based on the above functions, we can preliminarily design the DataMapping class:
Public ClassDataMapping
{
PublicDataMapping ()
{}
/// <Summary>
///Fill a dataset
/// </Summary>
Public VoidFill ()
{
}
/// <Summary>
///Set the update command
/// </Summary>
Public VoidSetCommands ()
{
}
/// <Summary>
///Set Data to submit transactions
/// </Summary>
Public VoidSetTransaction ()
{
}
/// <Summary>
///Submit data
/// </Summary>
Public BoolUpdate ()
{
}
/// <Summary>
///Update column name
/// </Summary>
Public StringColumns
{
Get
{
ReturnColumns;
}
Set
{
Columns=Value;
}
}
Private StringColumns= "";
/// <Summary>
///Primary Key name
/// </Summary>
Public StringKeyColumns
{
Get
{
ReturnKeyColumns;
}
Set
{
KeyColumns=Value;
}
}
Private StringKeyColumns= "";
/// <Summary>
///Table Name
/// </Summary>
Public StringTableName
{
Get
{
ReturnTableName;
}
Set
{