1024programmer Asp.Net The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper.

The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper.

The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper

Supports .Net Core (2.0 and above) and .Net Framework (4.0 and above) (Note: After upgrade, it can cover the early .Net Framework 4.0, and the problem of error reporting when the database field is Null has been fixed, invincible!!)

This tool is provided in the IDataAccess interface. Has been adopted by many major manufacturers in the .Net circle!

The namespace where IDataAccess is located is: DeveloperSharp.Framework.QueryEngine (need to reference the latest DeveloperSharp package from NuGet)

It mainly provides the following four major functions:

(1) Execute Sql statement

(2) Execute Sp stored procedure

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

(4) Business

The code for its initialization is as follows:

If you are in a .Net Core environment, the code is as follows:

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

    //In Startup.cs or Program  .cs file
    Services.AddTransient((t) => {
        DatabaseInfo DIF;
        DIF.DatabaseType = DatabaseType.SQLServer; //Set database type
        DIF.ConnectionString = "Server=localhost  ;Database=YZZ;Uid=sa;Pwd=123";
        return DataAccessFactory.Create  (DIF);
    });

If you are in a .Net Framework environment, the 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);

Note: By setting the DatabaseType attribute, support for all types of databases is provided (including: MySql, Oracle, PostgreSQL, SqlServer , Sqlite, Access, ODBC, etc.)

[Example 1: Query]

Below, firstly, a usage example of “querying multiple data + selecting single data + parameters” is given directly. The code is as follows:

 //Query multiple data  
    var Students1 = IDA.SqlExecute("select * from t_Student");

    //Many queries  Data (with parameters)
    var Students2 = IDA.SqlExecute("select * from t_Student where Id>@IdMin and Name like @LikeName", new { IdMin = 2, LikeName = "%week%" });
    //Another  One way of writing 1
    var IdMin = IDA.CreateParameterInput("  IdMin"  span>, DbType.Int32, 2  );
    params IDataParameter[] Params) where T : class, new()
 Purpose: Execute Sql statement (Select class)
 Parameters: (1)string cmdText -- Sql statement
      (2)object   InputParams -- Input parameter object
      (3)params   IDataParameter[] Params -- Parameter group
 Return: IEnumerable -- Multiple data result set

 SqlExecute (asynchronous: SqlExecuteAsync)
 Statement: int SqlExecute(string cmdText, params IDataParameter[] Params)
 Purpose: Execute Sql statement (Insert/Update/Delete class)
 Parameters: (1)string cmdText -- Sql statement
      (2)params   IDataParameter[] Params -- Parameter group
 Return: int -- Number of rows affected

 SqlExecute (asynchronous: SqlExecuteAsync)
 Statement: int SqlExecute(string cmdText, object InputParams, params IDataParameter[] Params)
 Purpose: Execute Sql statement (Insert/Update/Delete class)
 Parameters: (1)string cmdText -- Sql statement
      (2)object   InputParams -- Input parameter object
      (3)params   IDataParameter[] Params -- Parameter group
 Return: int -- Number of rows affected

 SpExecute (Asynchronous: SpExecuteAsync)
 Statement: IEnumerable SpExecute(string cmdText, params IDataParameter[] Params) where T : class, new()
 Purpose: Execute Sp stored procedure (Select class)
 Parameters: (1)string cmdText -- Sp stored procedure name
      (2)params   IDataParameter[] Params -- Parameter group
 Return: IEnumerable -- Multiple data result set

 SpExecute (Asynchronous: SpExecuteAsync)
 Statement: IEnumerable SpExecute(string cmdText, object InputParams, params IDataParameter[] Params) where T : class, new()
 Purpose: Execute Sp stored procedure (Select class)
 Parameters: (1)string cmdText -- Sp stored procedure name
      (2)object   InputParams -- Input parameter object
      (3)params   IDataParameter[] Params -- Parameter group
 Return: IEnumerable -- Multiple data result set

 SpExecute (asynchronous: SpExecuteAsync)
 Statement: int SpExecute(string cmdText, params IDataParameter[] Params)
 Purpose: Execute Sp stored procedure (Insert/Update/Delete class)
 Parameters: (1)string cmdText -- Sp stored procedure name
      (2)params   IDataParameter[] Params -- Parameter group
 Return: int -- Number of rows affected

 SpExecute (asynchronous: SpExecuteAsync)
 Statement: int SpExecute(string cmdText, object InputParams, params IDataParameter[] Params)
 Purpose: Execute Sp stored procedure (Insert/Update/Delete class)
 Parameters: (1)string cmdText -- Sp stored procedure name
      (2)object   InputParams -- Input parameter object
      (3)params   IDataParameter[] Params -- Parameter group
 Return: int -- the number of affected rows

KnotTail


The following is my official account, which contains many high-value technical articles, which are experiences that you cannot accumulate even if you work hard, and can help individuals grow rapidly.

You can also join us (add WeChat: 894988403, remark “join the group”), learn from the big guys, explore the industry insiders, and enjoy the opportunities of the times.

lor: rgba(128, 0, 128, 1)”>2)object InputParams — Input parameter object
(
3)params IDataParameter[] Params — Parameter group
Return: IEnumerable
Multiple data result set

SpExecute (asynchronous: SpExecuteAsync)
Statement: int SpExecute(string cmdText, params IDataParameter[] Params)
Purpose: Execute Sp stored procedure (Insert
/Update/Delete class)
Parameters: (
1)string cmdText — Sp stored procedure name
(
2)params IDataParameter[] Params — Parameter group
Return:
int Number of rows affected

SpExecute (asynchronous: SpExecuteAsync)
Statement: int SpExecute(string cmdText, object InputParams, params IDataParameter[] Params)
Purpose: Execute Sp stored procedure (Insert
/Update/Delete class)
Parameters: (
1)string cmdText — Sp stored procedure name
(
2)object InputParams — Input parameter object
(
3)params IDataParameter[] Params — Parameter group
Return:
int — the number of affected rows

KnotTail


The following is my official account, which contains many high-value technical articles, which are experiences that you cannot accumulate even if you work hard, and can help individuals grow rapidly.

You can also join us (add WeChat: 894988403, remark “join the group”), learn from the big guys, explore the industry insiders, and enjoy the opportunities of the times.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/the-real-artifact-for-executing-sql-statements-stored-procedures-if-you-dont-need-an-orm-choose-it-its-better-than-dapper/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索