Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper (connection.Query or connection.Execute)

I see the example of using Dapper in executing stored procedures with dynamic parameters, and returning the results of the procedure. Usually, the examples use .Execute, but a few of them use .Query. I have difficulty in using .Execute. Which am I supposed to use in the case described above--query or execute AND in what cases would I use each?

like image 717
Kevin Earley Avatar asked Oct 02 '12 16:10

Kevin Earley


1 Answers

If you need to return a value, then use Query(). If you need to execute a query that does not return anything, an update for example, then use Execute().

Query example:

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

Execute example:

connection.Execute("update myTable set columnA = @value", new {value = "ABC"})
like image 199
Void Ray Avatar answered Sep 26 '22 00:09

Void Ray