Build your own data access layer (2)

Source: Internet
Author: User

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
{

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.