What causes “extension methods cannot be dynamically dispatched” here?

So, can somebody please help me understand why leveraging the same overload inside of those other methods is failing with that error? Precisely because you’re using a dynamic value (param) as one of the arguments. That means it will use dynamic dispatch… but dynamic dispatch isn’t supported for extension methods. The solution is simple though: … 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

Dapper and SQL Injections

How does Dapper help protect against SQL injections? It makes it really, really easy to do fully parameterized data access, without ever needing to either concatenate input. In particular, because you don’t need to jump through lots of “add parameter, set the parameter type, check for null because ADO.NET has sucky null-handling, rinse/repeat for 20 … 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

Dapper.Rainbow VS Dapper.Contrib

I’ve been using Dapper for a while now and have wondered what the Contrib and Rainbow projects were all about myself. After a bit of code review, here are my thoughts on their uses: Dapper.Contrib Contrib provides a set of extension methods on the IDbConnection interface for basic CRUD operations: Get Insert Update Delete The … Read more

How do I handle Database Connections with Dapper in .NET?

Update: clarification from MarredCheese’s comment: “No need to use a using statement. Dapper will automatically open, close, and dispose of the connection for you.” That’s not correct. Dapper will automatically open closed connections, and it will automatically close connections that it auto-opened, but it will not automatically dispose of connections. Marc Gravell and Eric Lippert … Read more

Closing connection when using Dapper

I am assuming that you are using latest version of Dapper. With Dapper, there are two ways to manage connection: Fully manage yourself: Here, you are fully responsible for opening and closing connection. This is just like how you treat connection while working with ADO.NET. Allow Dapper to manage it: Dapper automatically opens the connection … Read more