1. Installation and use of mybatisnet

Source: Internet
Author: User

The use of a few DLLs supposedly should be to the official website to download, but this official website is gu eldest brother, do not know is not to be blocked, always open, fortunately from someone else's program copied over a copy, directly put in their own program on the line!

The program structure is as follows:

Providers.config,sqlmap.config,tuser.xml is a must. Tuser.xml is the configuration file corresponding to the TUser.cs entity class ( note the file name, the class name should be the same, the different situation seems to be wrong )

Providers.config as follows:

<?XML version= "1.0" encoding= "Utf-8"?><providersxmlns= "Http://ibatis.apache.org/providers"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">  <Clear/>  <providername= "sqlServer2.0"Description= "Microsoft SQL Server 7.0/2000/2005, provider V2.0.0.0 in framework. NET V2.0"enabled= "true"default= "true"AssemblyName= "System.Data, version=, Culture=neutral, publickeytoken=b77a5c561934e089"Connectionclass= "System.Data.SqlClient.SqlConnection"Commandclass= "System.Data.SqlClient.SqlCommand"Parameterclass= "System.Data.SqlClient.SqlParameter"Parameterdbtypeclass= "System.Data.SqlDbType"Parameterdbtypeproperty= "SqlDbType"Dataadapterclass= "System.Data.SqlClient.SqlDataAdapter"Commandbuilderclass= "System.Data.SqlClient.SqlCommandBuilder"usepositionalparameters= "false"Useparameterprefixinsql= "true"Useparameterprefixinparameter= "true"Parameterprefix="@"/></providers>

Sqlmap.config as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Sqlmapconfigxmlns= "Http://ibatis.apache.org/dataMapper"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">  <Settings>    <settingusestatementnamespaces= "false"/>    <settingcachemodelsenabled= "true"/>  </Settings>  <!--DB provider configuration file path -  <providersResource= "Providers.config"/>  <!--DB provider type and connection string -  <Database>    <providername= "sqlServer2.0" />    <!--<datasource name= "SQL Server" connectionstring= "Data SOURCE=ORCL; Persist Security info=true; User Id=scott; Password=tiger; Unicode=true "/> -    <DataSourcename= "SQL Server"connectionString= "Data source= (local); Initial Catalog=mybatis; User Id=sa; password=anyqu989125; " />      </Database>  <!--DB vs. entity mapping file -  <Sqlmaps>    <SqlmapResource= "Tuser.xml"/>  </Sqlmaps></Sqlmapconfig>

Tuser.xml as follows:

<?XML version= "1.0" encoding= "Utf-8"?><!--============================================================================//caution:this file is generated by IBATISNETGEN.BATISMAP.CST at 2014-10-22 13:59:11//any manual editing would be lost in re-generation.//== ========================================================================= -<Sqlmapnamespace= "Mybatisdemo"xmlns= "Http://ibatis.apache.org/mapping"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">   <alias>    <Typealiasalias= "TUser"type= "Mybatisdemo.tuser" />  </alias>  <Resultmaps>    <ResultmapID= "Fullresultmap"class= "TUser">      <result Property= "UID"column= "u_id"DbType= "Int"/>      <result Property= "UName"column= "U_name"DbType= "VarChar"/>      <result Property= "Udept"column= "U_dept"DbType= "VarChar"/>    </Resultmap>  </Resultmaps>  <Statements>    <InsertID= "Insert"Parameterclass= "TUSER">INSERT into [dbo]. [T_user] ([u_id], [U_name], [u_dept]) VALUES (#UID, dbtype=int#, #UName, dbtype=varchar#, #UDept, dbtype=varchar#)</Insert>  </Statements></Sqlmap>

The entity classes are as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacemybatisdemo{//==============================================================================    /// <summary><c>TUSER</c>Business Object.</summary>[Serializable] Public Partial classTUSER {#regionUidPrivateInt32 M_uid; /// <summary>Gets or sets UID</summary>         PublicInt32 UID {Get{returnM_uid;} Set{M_uid =value;} }        #endregion        #regionUNamePrivateString M_uname; /// <summary>Gets or sets UName</summary>         PublicString UName {Get{returnM_uname;} Set{M_uname =value;} }        #endregion        #regionUdeptPrivateString m_udept; /// <summary>Gets or sets udept</summary>         PublicString udept {Get{returnm_udept;} Set{m_udept =value;} }        #endregion    }}

The three configuration files mentioned above must be placed under Debug. Also note that the file name of the entity class, the class name, all the places in the configuration file involving the class name should be consistent, otherwise you will not be prompted to create the Sqlmap object because Productmap.xml is not found, the error is as follows:

Find a day of reason, always thought is the program of productmap.xml problem, but can't find this file, later understand this file is defined in the framework of the entity configuration Class A synonym. View the details in the error below:

1. Installation and use of mybatisnet

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.