I would like to ask if what is the best to use when INSERTING, UPDATING, DELETING, REMOVING, QUERY SPECIFIC DATA using DAPPER? I'm really confused in using EXECUTE and QUERY command in DAPPER..
C# – Comparing QUERY and EXECUTE in Dapper
cdapper
Related Topic
- C# – LINQ’s Distinct() on a particular property
- C# – How would you count occurrences of a string (actually a char) within a string
- C# – When to use .First and when to use .FirstOrDefault with LINQ
- C# – Performing Inserts and Updates with Dapper
- Sql – SELECT * FROM X WHERE id IN (…) with Dapper ORM
- C# – reason for C#’s reuse of the variable in a foreach
- C# – Try-catch speeding up the code
- Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
Best Answer
This should not be confusing at all, especially if you look at the signature of the methods exposed by the Dapper (as per documentation):
Query method is specifically meant for executing a select statement internally, which can return the
IEnumerable of a type T
, there are options to execute it, if done usinganonymous parameter
, then you are not expecting anyreturn value
orOutput parameter
, it just takesinput parameter
and provide the result, which has schema matching to the properties ofType T
. In casereturn value
orOutput parameter
is required, then that needs to be bound usingDynamicParameters
Execute method is meant for executing the DML statements, like
Insert, Update and Delete
, whose purpose is to make changes to the data in the database. The return type is aninteger
, which should contain the value of number of rows updated, if in SQL Server we have setSet RowCount On
, this call will not help in returning the Result Set, its only for DML calls.In case you need multiple result set then we have
QueryMultiple
. which returns aGridReader
and can be used to return the result of multiple Select statements, using a concept of MARS (Multiple active result set).Practically if your aim is just to execute a procedure, any of them would do, but what is more important is what result set are looking forward to receive, they all have different return to provide results