Ibatisnet.datamapper 1.6.1.0 Application ibatis.net simple three-layer demo & application scene

Source: Internet
Author: User
Tags config

The author of the enterprise is ready to use ibatis.net to do data access, so have this essay.

In the example, for convenience, the data binding for the foreground takes the data source. Through this essay, can let have not contacted Ibatis.net and plan to learn it people have a quick understanding and start!

First, we introduce the architecture of solution, which is divided into four projects:

WEB: Foreground application;

BLL: Business processing layer, if too troublesome, can be further abstracted, and then put the code into the Web layer of the aspx.cs inside;

Model: This is not much said, the Earth people know (data entity Class)

Sqlmaps: Resource class, package the configuration file and the SQL mapper file.

Two folders:

DLL file for Include:iBatis.Net schema

LOG: folder where log files are placed, configured in Web.config:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="../Log/log.txt"/>

Here, the main introduction is the Sqlmaps project.

Sqlmaps Project Document Introduction:

Sqlmap.config:iBatis.Net architecture is the most important configuration files, there are mainly properties,provider,database,sqlmaps configuration, this does not have to introduce more, a look will know. In addition, this essay helps you get started, and if you want to understand the meaning of each parameter in detail, it is recommended to see the Ibatis.net help manual.

Database.config: As the name suggests, the database connection configuration file, this file is the Sqlmap.config for the properties of the preparation, you can change to other names can also, even can not. See the configuration in Sqlmap.config:

<properties embedded= "Database.config,service.sqlmaps"/>

Providers.config:iBastis.Net, do not need to modify.

Mapsqlclientperson.xml: This is the legendary SQL mapper file, which is located in the Sqlmap.config:

<sqlMaps>
        <!-- user via embedded-->
        <sqlMap embedded="Map.SqlClient.Person.xml,Service.SqlMaps"/>
</sqlMaps>

It supports:

Storage process

Inline SQL

Motion SQL

Orm

5.codemybatis.cs: A processing class that is designed to initialize IBatisNet.DataMapper.ISqlMapper (because it is related to configuration and therefore packaged). Here, the support output DataTable and dataset are added. In addition, when the output is a DataTable or DataSet, the Resultmaps in the person.xml does not work, so the SQL statement will be configured:

<select id="SelectAllPerson2" resultMap="SelectAllResult">
   select
   PER_ID AS Id,
   PER_FIRST_NAME AS FirstName,
   PER_LAST_NAME AS LastName,
   PER_BIRTH_DATE AS BirthDate,
   PER_WEIGHT_KG AS WeightInKilograms,
   PER_HEIGHT_M AS HeightInMeters
   from PERSON
   <dynamic prepend="WHERE">
     <isParameterPresent>
       PER_FIRST_NAME LIKE #FirstName#+'%'
     </isParameterPresent>
   </dynamic>
</select>

It is recommended that the attributes of the entity class be consistent with the database table fields so that everyone can worry!

6.Script: The SQL statement for the tables and data used in the example.

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.