I am very impressed with the results of Dapper Micro ORM for stackoverflow.com. I am considering it for my new project and but I have one concern about that some times my project requires to have Stored Procedure and I have search a lot on web but not found anything with stored procedure. So is there any way to have Dapper work with a stored procedure?
Please let me know if it is possible otherwise I have to extend it in my way.
I think the answer depends on which features of stored procedures you need to use.
Stored procedures returning a result set can be run using
Query
; stored procedures which don't return a result set can be run usingExecute
- in both cases (usingEXEC <procname>
) as the SQL command (plus input parameters as necessary). See the documentation for more details.As of revision 2d128ccdc9a2 there doesn't appear to be native support for
OUTPUT
parameters; you could add this, or alternatively construct a more complexQuery
command which declared TSQL variables, executed the SP collectingOUTPUT
parameters into the local variables and finallyreturned them in a result set:Same from above, bit more detailed
Using .Net Core
Controller
Stored Procedure ( parent child relation )
References in case
In the simple case you can do:
If you want something more fancy, you can do:
Additionally you can use exec in a batch, but that is more clunky.
Here is code for getting value return from Store procedure
Stored procedure:
Code:
With multiple return and multi parameter