Why Entity Framework performs faster than Dapper in direct select statement [closed]

ORM (Object Relational Mapper) is a tool that creates layer between your application and data source and returns you the relational objects instead of (in terms of c# that you are using) ADO.NET objects. This is basic thing that every ORM does. To do this, ORMs generally execute the query and map the returned DataReader … Read more

Dapper and anonymous Types

Is it possible to use anonymous types with Dapper? Sure see the non-generic Query override, it return a dynamic IDictionary<string, object> this object is an expando that can either be cast or accessed with dot notation. Eg: var v = connection.Query(“select 1 as a, 2 as b”).First(); Console.Write(“{0} {1}”,v.a, v.b) // prints: 1 2 is … Read more

When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id”, “splitOn

You need to include the column you’d want to split on in your select query. Yours just selects all the other properties – so Dapper doesn’t find a matching column to split the objects. Your query should probably be something like that: var query = @”SELECT AlbumId, Title, Price, AlbumArtUrl, GenreId, Name, Description , ArtistId, … Read more

Is there any way to trace\log the sql using Dapper?

I got the same issue and implemented some code after doing some search but having no ready-to-use stuff. There is a package on nuget MiniProfiler.Integrations I would like to share. Update V2: it supports to work with other database servers, for MySQL it requires to have MiniProfiler.Integrations.MySql Below are steps to work with SQL Server: … Read more

CancellationToken with async Dapper methods?

You are passing the cancellation token as the parameter object; that won’t work. The first async methods in dapper did not expose a cancellation token; when I tried to add them as an optional parameter (as a separate overload, to avoid breaking existing assemblies), things got very confused with “ambiguous method” compilation problems. Consequently, I … Read more

Simple inner join result with Dapper?

You can do something like this (see https://www.tritac.com/blog/dappernet-by-example): public class Shop { public int? Id {get;set;} public string Name {get;set;} public string Url {get;set;} public IList<Account> Accounts {get;set;} } public class Account { public int? Id {get;set;} public string Name {get;set;} public string Address {get;set;} public string Country {get;set;} public int ShopId {get;set;} } var … Read more

Latest Dapper VS Entity Framework 6 performance considerations

Does anyone have any updates on performance regarding EF 6.1.x? This concerns general queries made within a DbContext? Ans: I don’t have specific numbers, but I have updated the performance rig to EF6; I can’t remember the outcome exactly, but: EF6 is a lot faster than EF-old, but dapper is still significantly faster in many … Read more

How to pass a null parameter with Dapper

I think you should be able to do it by casting null to the appropiate type. Let’s assume RouteId is an integer: connection.Execute(“spLMS_UpdateLMSLCarrier”, new { RouteId = (int?)null, CarrierId = carrierID, UserId = userID, TotalRouteRateCarrierId = totalRouteRateCarrierId }, commandType: CommandType.StoredProcedure); The problem you are encountering when using regular null is likely that the compiler cannot … Read more

How to return dynamic types List with Dapper ORM

Sure! As per dapper documentation use the query method and get your dymanics: dynamic account = conn.Query<dynamic>(@” SELECT Name, Address, Country FROM Account WHERE Id = @Id”, new { Id = Id }).FirstOrDefault(); Console.WriteLine(account.Name); Console.WriteLine(account.Address); Console.WriteLine(account.Country); As you can see you get a dynamic object and you can access its properties as long as they … Read more

Getting “The connection does not support MultipleActiveResultSets” in a ForEach with async-await

You need to add attribute MultipleActiveResultSets in connection string and set it to true to allow multiple active result sets. “Data Source=MSSQL1;” & _ “Initial Catalog=AdventureWorks;Integrated Security=SSPI;” & _ “MultipleActiveResultSets=True” Read more at: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)