Dapper vs. ADO.Net with reflection, which is faster?

I studied Dapper and ADO.NET and ran random tests for both and found that sometimes ADO.NET is faster than Dapper, and sometimes vice versa. I understand that this may be a database problem as I am using SQL Server. As indicated, reflection is slow and I'm using reflection in ADO.NET. So can anyone tell me which approach is the fastest?

Here is what I encoded.

  • Using ADO.NET

    DashboardResponseModel dashResp = null;
    SqlConnection conn = new SqlConnection(connStr);
    try
    {
        SqlCommand cmd = new SqlCommand("spGetMerchantDashboard", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@MID", mid);
        conn.Open();
        var dr = cmd.ExecuteReader();
    
    List<MerchantProduct> lstMerProd = dr.MapToList<MerchantProduct>();
    List<MerchantPayment> lstMerPay = dr.MapToList<MerchantPayment>();
    
    if (lstMerProd != null || lstMerPay != null)
    {
        dashResp = new DashboardResponseModel();
        dashResp.MerchantProduct = lstMerProd == null ? new 
        List<MerchantProduct>() : lstMerProd;
        dashResp.MerchantPayment = lstMerPay == null ? new 
        List<MerchantPayment>() : lstMerPay;
    }
    
    dr.Close();
    
    }
    
    return dashResp;
    
  • Using Dapper

    DashboardResponseModel dashResp = null;
    
    var multipleresult = db.QueryMultiple("spGetMerchantDashboard", new { mid = 
    mid }, commandType: CommandType.StoredProcedure);
    var merchantproduct = multipleresult.Read<MerchantProduct>().ToList();
    var merchantpayment = multipleresult.Read<MerchantPayment>().ToList();
    
    if (merchantproduct.Count > 0 || merchantpayment.Count > 0)
    dashResp = new DashboardResponseModel { MerchantProduct = 
    merchantproduct, MerchantPayment = merchantpayment };
    
    return dashResp;
    
0
source share
2 answers

Dapper ADO.NET - , ADO.NET(, : ADO.NET).

; , Dapper ( - , ), , / DSL, , , , ORM , .

; , , - ( MerchantProduct ) IL-emit -. . , .

( RDBMS + + ) , , .

: , .

: AsList() ToList(), .

+2

:

Dapper - micro-ORM Data Mapper. ADO.NET. , Dapper ADO.NET(DataReader, ) POCO. , Dapper, , ADO.NET.

(@MarcGravell) this:

, API, ; , , , ADO.NET - , ADO.NET, , , ..; DataTable:)

, ADO.NET . ; ADO.NET. ADO.NET , , Dapper. , ADO.NET Dapper.

:

Dapper ( ) ADO.NET. Dapper , ADO.NET, . , ADO.NET, ( ).

Dapper, IL. Dapper , .

, , Dapper : https://samsaffron.com/archive/2011/03/30/How+I+learned+to+stop+worrying+and+write+my+own+ORM

Dapper :

  • ( ), Dapper . ADO.NET. , - Dapper ; , . , Dapper buffered; false, Dapper . . @Marc.

  • Dapper , IDbConnection. . , , Dapper, .

  • Dapper . . .

, . .

Dapper ( ORM ADO.NET), ; , .

0

Source: https://habr.com/ru/post/1690704/


All Articles