Monday, June 20, 2011

PetaPoco with stored procedures

In previous post I have written that How we can use PetaPoco with the 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.
using System.Collections.Generic;

namespace CodeSimplified.Models
  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.

Shout it

kick it on

1 comment:

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews