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;
Dapper ADO.NET - , ADO.NET(, : ADO.NET).
; , Dapper ( - , ), , / DSL, , , , ORM , .
; , , - ( MerchantProduct ) IL-emit -. . , .
MerchantProduct
( RDBMS + + ) , , .
: , .
: AsList() ToList(), .
AsList()
ToList()
Dapper - micro-ORM Data Mapper. ADO.NET. , Dapper ADO.NET(DataReader, ) POCO. , Dapper, , ADO.NET.
DataReader
(@MarcGravell) this:
, API, ; , , , ADO.NET - , ADO.NET, , , ..; DataTable:)
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 . ADO.NET. , - Dapper ; , . , Dapper buffered; false, Dapper . . @Marc.
buffered
false
Dapper , IDbConnection. . , , Dapper, .
IDbConnection
Dapper . . .
, . .
Dapper ( ORM ADO.NET), ; , .
Source: https://habr.com/ru/post/1690704/More articles:Checking an item in a list box Ignoring - stringПочему компилятор выводит разное время жизни для характеристики и ее реализации? - rustIs AsList () better than ToList () with IDbConnection.Query (), which returns IEnumerable? - performanceFirst time call function in node - node.jsКак удалить список <Объект> в Netty - javaAngular Material 2 Autocomplete with Angular 5 - autocompleteVisual Studio Android SDK Manager Android 8.1.0 API 27 ошибка "Загрузка завершена с неправильным размером. Ожидаемое 65606517 байт, получено 65738431 байт" - androidChanging post webpack build configuration values - javascriptSave location in mongodb - node.jsИнтеграция тестирования данных мусора - c#All Articles