Dapper (connection.Query or connection.Execute)

I see an example of using Dapper when executing stored procedures with dynamic parameters and returning the results of the procedure. Typically, examples use .Execute, but some of them use .Query. I find it difficult to use .Execute. What should I use in the case described above - to request or execute And in what cases will I use each?

+7
source share
1 answer

If you need to return a value, use Query (). If you need to execute a query that returns nothing, such as an update, then use Execute ().

Request example:

var myList = connection.Query("select * from myTable") 

Execution Example:

 connection.Execute("update myTable set columnA = @value", new {value = "ABC"}) 
+12
source

All Articles