User Id :    Password :      New Member   Forgot Password  
PetaPoco with stored procedures
Description PetaPoco with stored procedures in MVC.   No. of Views     1529
  Rating     0
Author Jalpesh Vadgama   Posted On     24 Jun 2011
Tags SQL SERVER,ASP.NET-MVC,.NET 3.5,General    

Sample Code   Download Code


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.




About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at Jalpesh Vadgama
No Photo
Country India
Company N/A
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Write your comment here.
Verification Code