After spending a week learning about Umbraco in great Copenhagen I’m finally at the goal.




Thanks Per @perploughanse and Sebastiaan @cultiv for a great course!


And by the way if you are planning to attend a course, don’t go to “Billy Booze”-bar the night before. Bad idea.

I actually started working on this blog post when i was i Thailand over Christmas. I sat down at the beach cafe by our hotel and my view looked something like this:



Perfect condition for reading the new Umbraco 6 source code! =D

New data layer using PetaPoco

The new data layer in Umbraco 6 is using the superfast Mirco ORM PetaPoco which is aaaaalmost as fast as hand coding the SQL queries with the ADO.NET classes – any case it’s a lot faster then ie. EF or nHibernate.


I used PetePoco in one of my projects about a year ago and I’m very happy with how it works. The implementation in Umbraco is even better than the “standard” PetaPoco as it comes with some extra classes and helper that helps you make the SQL-queries even more database agnostic.

Demo 1.0

Just to show you how simple it is to use the new data layer to fetch data from custom tables I’ll show you the simplest example.


I this example we have a custom table in the Umbraco database called 'ext_Contacts' which has three columns: ContactId, Name and Phone. First we create a POCO class to act as our model.


public class Contact
  public Int32 ContactId { get; set; }
  public String Name{ get; set; }
  public String Phone{ get; set; }

This object has no idea of what context it’s used in, it doesn't know anything about Umbraco, PetaPOCO or any other infrastructure in the project. To use the Umbraco data layer to receive a collection of contacts from the database you just simply use the this code:


// Get the current database object
var db = ApplicationContext.Current.DatabaseContext.Database;
// Fetch a collection of contacts from the db.
var listOfContacs = db.Fetch<Contact>(new Sql().Select("*").From("ext_Contacts"));


 This code looks like any other PetaPOCO implementation and you could download a stand alone version of PetaPOCO and use this in you own (non Umbraco) project in the same way. The Fetch-method is smart enough to grab the data from the db-table and map it to the Contact-object. If your properties don’t match the column name you will need to do some configuration to get this working.


The great thing with this code is that it will work no matter which database you are running on – you don’t have to care. I’m going to use this approach in the next version of Newsletter Studio for Umbraco to rewrite the data access layer to not use EF any more.


With all this said you should not use this method to fetch content, media, members or anything else from the Umbraco core – then you should use the new Services that Niels Hartvig explains in this blog post.

Today I started the first day at the level 1 course for Umbraco CMS. Most off the stuff that we talked about was very basic but I did find out some new tips and tricks that I would like to share with you.


Umbraco course in Copenhagen january 2013


Creating custom templates for scripting files

When you create a new macro script you will get a list of pre defined templates that you can start from.

Create new scripting file in Umbracos backoffice


If you want to extend this list with your own custom templates it’s very easy. Just drop your template as a “.cshtml”-file inside of the folder “\umbraco\scripting\templates\cshtml\” and your set.

Same thing goes for XSLT-templates but they are stored in “\umbraco\xslt\templates\”. If you macro template uses the new schema put it in “\umbraco\xslt\templates\Schema2\”


Highlight the current menu item

When looping out menu items I used to run a check to see if the current page id is equal to the current item in the rendered collection. If so – I added some kind of class to the generated link to indicate that this is the currently selected menu item.

Today i discovered this little Razor-helper: @nodeItem.IsAnsestorOrSelf(Model, "current", "").

I’m not sure how long it’s been there but since I often start coding from old bootstrap-projects I’ve missed this little helpful feature. If you want to have a look at it, create a new macro script in the developers section and choose the “Navigation” template.


    @*Get the root of the website *@
    var root = Model.AncestorOrSelf(1);
    @foreach (var page in root.Children.Where("Visible"))
        <li class="@page.IsAncestorOrSelf(Model, "current", "")">
            <a href="@page.Url">@page.Name</a>

The “Razor snippets”-article from contains a lot of great tips and tricks and also the Razor Cheat Sheet is good to have!


new headline


Last week i discovered a great resource for information about Umbraco. It's a christmas calendar that contains 24 blog posts about Umbraco and how to use it. I would like to present some of my favorite posts here.


Focus on the editors

The editors are the people who will use the system the most. Thats why I love these posts about how to make Umbraco easier to use for our editors:


Developers goodies

Another great topic is speed. I see far to many pages that are slow because the developers don´t implemented a good cache-strategy - I love the quote "not running code is the fastes way to improve you applications speed".


Matt Brailsford shows a very simple way to implement paging using Umbraco: simple paging


The new Image control in Umbraco version 4.11 is described here:

All the posts can be found here:


Tomorrow I'm getting on a plane to the south of Sweden and on tuesday I will attend the Umbraco course in Copenhagen! =D I'll try to write some blog posts during the week - I'm working on a post about the new data layer in Umbraco 6 based on the great micro orm PetaPoco.