In previous post I have written that How we can use PetaPoco with the asp.net MVC. One of my dear friend Kirti asked me that How we can use it with Stored procedure. So decided to write a small post for that. So let’s first create a simple stored procedure for customer table which I have used in my previous post. I have written simple code a single query that will return customers. Following is a code for that.
CREATE PROCEDURE mysp_GetCustomers
SELECT * FROM [dbo].Customer
Now our stored procedure is ready so I just need to change my CustomDB file from the my previous post example like following.
public class CustomerDB
public IEnumerable<Customer> GetCustomers()
var databaseContext = new PetaPoco.Database("MyConnectionString");
return databaseContext.Query<Customer>("exec mysp_GetCustomers");
That's It. Now It's time to run this in browser and Here is the output
In future post I will explain How we can use PetaPoco with parameterised stored procedure. Hope you liked it.. Stay tuned for more.. Happy programming.