Necessary for medium and large-scale project development of. NET -- ORM database access technology

Related downloads:

DeveloperSharp.dll component

DeveloperSharp.dll component

 

Common ORM technologies (such as Entity Framework, Dapper, SqlSugar, NHibernate, etc.) are either making procedural variants of Sql statements or object-oriented Sql statements. The disadvantages are obvious: it is difficult to popularize and apply simple Sql statements on a large scale without unified standards

And ADO Net also has some disadvantages, such as complex operation, and the operation code of different types of databases (SqlServer, MySql, Oracle, etc.) needs to be reconstructed.

The ORM database access technology in the developer sharp framework introduced in this paper skillfully avoids the above shortcomings and provides a set of compromise and perfect solutions, which are implemented in the IDataAccess interface.

 

The namespace of IDataAccess is: developer sharp Framework. QueryEngine.

It mainly provides the following four functions:

(1) Execute Sql statement

(2) Execute Sp stored procedure

(3) Create parameters (input / output / return)

(4) Business

Its initialization code is as follows:

using DeveloperSharp.Framework.QueryEngine;
--------------------------

   DatabaseInfo DIF;
   DIF.DatabaseType = DatabaseType.SQLServer; //Set database type
   DIF.ConnectionString = "Server=localhost;Database=YZZ;Uid=sa;Pwd=123";
   IDataAccess IDA = DataAccessFactory.Create(DIF);

 

The following is an example of using Sql statement + parameter + transaction. The code is as follows:

            try
            {
                //Open transaction
                IDA.TransactionBegin();

                //Execute with parameters Sql sentence
                var newQuantity = IDA.CreateParameterInput("newQuantity", DbType.Int32, 506);
                var newName = IDA.CreateParameterInput("newName", DbType.String, 50, "Hat");
                IDA.SqlExecuteNonQuery("update t_Order set Quantity=@newQuantity where Id=1", newQuantity);
                IDA.SqlExecuteNonQuery("update t_Order set Quantity=@newQuantity,Name=@newName  where Id=3", newQuantity, newName);

                //Complete transaction
                IDA.TransactionCommit();
            }
            catch
            {
                //Rollback transaction
                IDA.TransactionRollBack();
            }

Note: when creating parameters, DbType is used to transparently switch between different types of databases (SqlServer, MySql, Oracle, etc.)!

 

The detailed functions and methods in IDataAccess are described as follows:

DatabaseType
 Statement: DatabaseType DatabaseType{get;}
Purpose: get database type
 return: DatabaseType     --  Database type enumeration

ConnectionString
 Statement:string ConnectionString{get;}
Purpose: get database link string
 return:string    --  Database link string

CreateParameterInput
 Statement: IDataParameter CreateParameterInput(string name, DbType type, int size, object val)
Purpose: create input parameters
 Parameters:(1)string name      --  Parameter name
     (2)DbType type   --  Parameter type
     (3)int size        -- Parameter size
     (4)object val        --Parameter value
 return: IDataParameter     --  input parameter 

CreateParameterInput
 Statement: IDataParameter CreateParameterInput(string name, DbType type, object val)
Purpose: create input parameters
 Parameters:(1)string name      --  Parameter name
     (2)DbType type   --  Parameter type
     (3)object val        --Parameter value
 return: IDataParameter     --  input parameter 

CreateParameterOutput
 Statement: IDataParameter CreateParameterOutput(string name, DbType type, int size)
Purpose: create output parameters
 Parameters:(1)string name    --Parameter name
     (2)DbType type    --Parameter type
     (3)int size    --Parameter size
 return: IDataParameter    --  Output parameters

CreateParameterOutput
 Statement: IDataParameter CreateParameterOutput(string name, DbType type)
Purpose: create output parameters
 Parameters:(1)string name    --Parameter name
     (2)DbType type    --Parameter type
 return: IDataParameter    --  Output parameters

CreateParameterReturn()
Statement: IDataParameter CreateParameterReturn()
Purpose: create return parameters
 Parameters: (none)
return: IDataParameter    --  Return parameters

TransactionBegin
 Statement:void TransactionBegin()
Purpose: open transaction
 Parameter: (none)
Return: (none)

TransactionCommit
 Statement:void TransactionCommit()
Purpose: complete transaction
 Parameters: (none)
Return: (none)

TransactionRollBack
 Statement:void TransactionRollBack
 Purpose: rollback transaction
 Parameters: (none)
Return: (none)

SqlExecuteNonQuery
 Statement:int SqlExecuteNonQuery(string cmdText)
Purpose: Execution Sql Command text that returns the number of lines affected
 Parameters:(1)string  cmdText     -- Sql Command text
 return:int    --Number of rows affected

SqlExecuteNonQuery
 Statement:int SqlExecuteNonQuery(string cmdText , params IDataParameter[] cmdParameters)
Purpose: Execution Sql Command text that returns the number of lines affected
 Parameters:(1)string  cmdText     -- Sql Command text
     (2)params IDataParameter[] cmdParameters    --Command parameter array
 return:int    --Number of rows affected

SpExecuteNonQuery
 Statement:int SpExecuteNonQuery(string cmdText)
Purpose: Execution Store Procedure Command text that returns the number of lines affected
 Parameters:(1)string  cmdText    --Store Procedure Command text
 return:int    --Number of rows affected

SpExecuteNonQuery
 Statement:int SpExecuteNonQuery(string cmdText, params IDataParameter[] cmdParameters)
Purpose: Execution Store Procedure Command text that returns the number of lines affected
 Parameters:(1)string cmdText    -- Store Procedure Command text
     (2)params IDataParameter[] cmdParameters    --Command parameter array
 return:int        --Number of rows affected

SqlExecuteReader
 Statement: IDataReader SqlExecuteReader(string cmdText)
Purpose: Execution Sql Command text, returning DataReader object
 Parameters:(1)string  cmdText    -- Sql Command text
 return: IDataReader    -- DataReader object

SqlExecuteReader
 Statement: IDataReader SqlExecuteReader (string cmdText, params IDataParameter[] cmdParameters)
Purpose: Execution Sql Command text, return DataReader object
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)params IDataParameter[] cmdParameters    --Command parameter array
 return: IDataReader    -- DataReader object

SpExecuteReader
 Statement: IDataReader SpExecuteReader(string cmdText)
Purpose: Execution Store Procedure Command text, return DataReader object
 Parameters:(1)string  cmdText    -- Store Procedure Command text
 return: IDataReader    -- DataReader object

SpExecuteReader
 Statement: IDataReader SpExecuteReader(string cmdText, params IDataParameter[] cmdParameters)
Purpose: Execution Store Procedure Command text, returning DataReader object
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)params IDataParameter[] cmdParameters    --Command parameter array
 return: IDataReader    -- DataReader object

SqlExecuteScalar
 Statement:object SqlExecuteScalar(string cmdText)
Purpose: Execution Sql Command text, return sum,avg,max The value calculated by the equal aggregation function
 Parameters:(1)string  cmdText    -- Sql Command text
 return:object    --The value calculated by the aggregate function

SqlExecuteScalar
 Statement:object SqlExecuteScalar(string cmdText, params IDataParameter[] cmdParameters)
Purpose: Execution Sql Command text, return sum,avg,max The value calculated by the equal aggregation function
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)params IDataParameter[]  cmdParameters    --Command parameter array
 return:object    --The value calculated by the aggregate function

SpExecuteScalar
 Statement:object SpExecuteScalar(string cmdText)
Purpose: Execution Store Procedure Command text, returning sum,avg,max The value calculated by the equal aggregation function
 Parameters:(1)string  cmdText    -- Store Procedure Command text
 return:object    --The value calculated by the aggregate function

SpExecuteScalar
 Statement:object SpExecuteScalar(string cmdText, params IDataParameter[] cmdParameters)
Purpose: Execution Store Procedure Command text, returning sum,avg,max The value calculated by the equal aggregation function
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)params IDataParameter[] cmdParameters    --Command parameter array
 return:object    --The value calculated by the aggregate function

SqlExecuteDataset
 Statement:void SqlExecuteDataset(string cmdText, DataSet ds)
Purpose: Execution Sql Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)DataSet ds    --Dataset object
 Return: (none)

SqlExecuteDataset
 Statement:void  SqlExecuteDataset(string cmdText, DataSet ds, string tableName)
Purpose: Execution Sql Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)DataSet ds    --Dataset object
     (3)string tableName    --The name of the data table in the dataset
 Return: (none)

SqlExecuteDataset
 Statement:void SqlExecuteDataset(string cmdText, DataSet ds, params IDataParameter[] cmdParameters)
Purpose: Execution Sql Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)DataSet ds    --Dataset object
     (3)params IDataParameter[] cmdParameters    --Command parameter array
 Return: (none)

SqlExecuteDataset
 Statement:void SqlExecuteDataset(string cmdText, DataSet ds, string tableName, params IDataParameter[] cmdParameters)
Purpose: Execution Sql Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Sql Command text
     (2)DataSet ds    --Dataset object
     (3)string tableName    --The name of the data table in the dataset
     (4)params IDataParameter[] cmdParameters    --Command parameter array
 Return: (none)

SpExecuteDataset
 Statement:void SpExecuteDataset(string cmdText, DataSet ds)
Purpose: Execution Store Procedure Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)DataSet ds    --Dataset object
 Return: (none)

SpExecuteDataset
 Statement:void SpExecuteDataset(string cmdText, DataSet ds, string tableName)
Purpose: Execution Store Procedure Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)DataSet ds    --Dataset object
     (3)string tableName    --The name of the data table in the dataset
 Return: (none)

SpExecuteDataset
 Statement:void SpExecuteDataset(string cmdText, DataSet ds, params IDataParameter[] cmdParameters)
Purpose: Execution Store Procedure Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)DataSet ds    --Dataset object
     (3)params IDataParameter[] cmdParameters    --Command parameter array
 Return: (none)

SpExecuteDataset
 Statement:void SpExecuteDataset(string cmdText, DataSet ds, string tableName, params IDataParameter[] cmdParameters)
Purpose: Execution Store Procedure Command text, get the corresponding DataSet data set
 Parameters:(1)string  cmdText    -- Store Procedure Command text
     (2)DataSet ds    --Dataset object
     (3)string tableName    --The name of the data table in the dataset
     (4)params IDataParameter[] cmdParameters    --Command parameter array
 Return: (none)

 

Recommended reading

Keywords: SQL Server .NET orm

Added by manishdugar on Thu, 20 Jan 2022 05:03:40 +0200