I have studied about Dapper and ADO.NET and performed select tests on both and found that sometimes ADO.NET is faster than Dapper and sometimes is reversed. I understand this could be database issues as i am using SQL Server. As it is stated that reflection is slow and i am using reflection in ADO.NET. So can anyone tell me which approach is the fastest?
Here what i coded.
-
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;
Aucun commentaire:
Enregistrer un commentaire