小编Adn*_*ikh的帖子

Dapper vs ADO.Net用反射哪个更快?

我研究了Dapper和ADO.NET,并对两者进行了选择测试,发现有时ADO.NET比Dapper更快,有时会逆转.我知道这可能是数据库问题,因为我正在使用SQL Server.据说反射很慢,我在ADO.NET中使用反射.那么有谁能告诉我哪种方法最快?

这是我编码的.

  1. 使用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;
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用Dapper

    DashboardResponseModel dashResp …
    Run Code Online (Sandbox Code Playgroud)

c# reflection ado.net dapper

4
推荐指数
2
解决办法
6995
查看次数

标签 统计

ado.net ×1

c# ×1

dapper ×1

reflection ×1