Ibatisnet (datamapper)

Source: Internet
Author: User

Ibatisnet is a lightweight ORM open-source framework with simple configuration and ease of use.

Ibatisnet Official Website: http://ibatis.apache.org/dotnet.cgi

 

Ibatisnet has two projects: datamapper and dataaccess,

Datamapper is equivalent to Dal (data access layer) and provides data access interfaces. Separate the SQL statement from the original hard encoding TO THE. xml file.

The query results are returned to the call layer through map, list, and object .. After the launch of NET 2.0, ibatisnet's datamapper also supports generics,

With stronger type support. Its simple and easy-to-use dynamic SQL (configured using XML tags) makes ibatisnet more flexible and easy to use.

Dataaccess is critical between the dal and BLL (business logic layer). With dataaccess, You can flexibly change your dal, for example:

Two different databases must be operated simultaneously in the project. (The address may be different, or the database vendor may be different ). DB configuration is in providers. xml,

The Dal configuration is in Dao. config. With dataaccess, you can use datamapper to operate the database, or use a custom Dao object to access the database.

This is also a feature.

 

First, summarize the configuration of ibatisnet datamapper:

 

1. Add reference for the project:

Ibatisnet. Common. dll

Ibatisnet. datamapper. dll

 

2. To use datamapper, add the configuration file:

Sqlmap. config (configure the storage location of SQL files, corresponding dB type, connection string)

Providers. config (the DLL of the low-level data provider, don't worry about it)

 

The configuration of sqlmap. XML is described in detail.

Overall:
<Sqlmapconfig...>
<! -- 2. parameter file configuration -->
<Properties.../>
 
<! -- 3. Configure the database provider file -->
<Provider.../>

<Settings>
...
</Settings>

<! -- 4. Database Connection configuration -->
<Database>
<Provider.../>
<Datasource.../>
</Database>

<! -- SQL XML file configuration -->
<Sqlmaps>
<Sqlmap.../>
<Sqlmap.../>
</Sqlmaps>

</Sqlmapconfig>

1) Configure project parameters
You can use parameters to configure a name (attribute) or a name (attribute) that is easy to change.
For example: $ {username} in <datasource connectionstring = "User ID =$ {username};"/>}
In this way, $ {username} can be used throughout ibatis.
Such parameters are defined and assigned values in the parameter file, and then referenced in the properties configuration section. (2. parameter file configuration)

The format in the parameter file (for example, properties. config in 2.) is as follows:
<Settings>
<Add key = "username" value = "sa"/>
</Settings>

2) parameter file configuration
In the properties configuration section, configure the project parameters used in sqlmap. xml and other SQL XML.
There are three ways to reference the properties configured in the specified file.
A) The resource method (relative path) will find and load the configuration file with the specified name under the application directory.
<Properties resource = "properties. config"/>

B) The URL method (absolute path) will load the file with the specified absolute path based on the specified URL
<Properties url = "C:/web/MyApp/resources/properties. config"/>

C) the embedded mode (embedded Resource) will find and load the specified configuration file in the embedded Resource
<Properties embedded = "resources. properties. config, MyApp. Data"/>
Note: The properties. config file is placed under the Resources Directory of the project, and the "generate operation" attribute of the file is "embedded resource"

3) configure the database provider File
Provider configuration section, configure the database to provide Assembly (DLL) information.
Similar to the properties configuration section, there are also three methods (A, B, and C for 1-2): resource, URL, and embedded ).
The corresponding provider. config can be copied and used from ibatis. datamapper.1.6.2.bin.
Example: <provider resource = "provider. config"/>
[Note] set the enabled attribute of the assembly to "true" for the data to be used in provider. config"

4. Database Connection Configuration
In the Database Configuration section, configure database information.

5. typehandler configuration section

6. sqlmaps configuration section (declare the location of the SQL file)

 

 

 

 

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.