Fork me on GitHub
2sxc 9.33 for DNN 7 to 9
Website Builder, Content Manager, App-System: open-source and amazing
You are here: Home  >  Docs  >  Feature

PetaPoco Support

Introduced in Version 06.00.06
Demos of this feature

Technically, this has always been possible - but for lack of sample code people didn't know how to use it. So here goes:



       // for PetaPoco you must first create a class containing the fields you want

       private class fileRecord


             public int FileId { get; set; }

             public string FileName { get; set; }

             public int Size { get; set; }

             public int FolderId { get; set; }



       private IEnumerable<fileRecord> files;


       // Official place to provide data preparation. Is automatically called by 2SexyContent

       public override void CustomizeData()


             var sqlCommand = "Select Top 10 * from Files Where PortalId = @0"; // PetaPoco requires numbered parameters like @0 instead of @PortalId


             var db = new PetaPoco.Database(Content.ConnectionName);

             files = db.Query<fileRecord>(sqlCommand, Dnn.Portal.PortalId);




<div class="sc-element">


       <h1>Simple Demo with PetaPoco Data access</h1>

       <p>This demo uses PetaPoco as a mini-ORM to get the data. More info on <a href="" target="_blank">PetaPoco here</a>.</p>

       <h2>The top 10 files found in this portal as returned by PetaPoco</h2>


             @foreach (var file in files)


                    <li>@file.FileName (@file.FileId)</li>




Tags for this feature