Does anyone know if you can use PetaPoco to run a SQL select statement/stored procedure from a Microsoft SQL server? All of the examples I've found seem to be for returning data from one table (or inserting data into a table).
If PetaPoco can't do this does anyone know what can do it?
It has been a little bit since I have done this with PetaPoco so I am going off of memory, but I believe that you can pass in a custom SQL statement and have the result populate a custom model that is not a table in the database.
var results = DatabaseContext.Database.Fetch<MyCustomModel>("select col1, col2, col3 as [mycol] from mytable inner join blah blah blah");
If I am recalling correctly, the key is that the properties in your custom model need to be named exactly the same as the columns names return from your query. Hope that helps.
Running a custom SQL statement
Hi,
Does anyone know if you can use PetaPoco to run a SQL select statement/stored procedure from a Microsoft SQL server? All of the examples I've found seem to be for returning data from one table (or inserting data into a table).
If PetaPoco can't do this does anyone know what can do it?
Thanks, Jeff
It has been a little bit since I have done this with PetaPoco so I am going off of memory, but I believe that you can pass in a custom SQL statement and have the result populate a custom model that is not a table in the database.
If I am recalling correctly, the key is that the properties in your custom model need to be named exactly the same as the columns names return from your query. Hope that helps.
This might help also:
http://www.toptensoftware.com/Articles/101/PetaPoco-Working-with-Joins
Thanks Jason, that's sorted it!
Hi Jason,
Are there any major advantages to using PetaPoco than WebMatrix.Data?
To be honest I am not familiar with WebMatrix.Data. Personally I would use PetaPoco since it is baked into Umbraco.
is working on a reply...