Navigation and service panel


Content

Glass Mapper V4 and auto-generate models without TDS

By Kevin Brechbühl on 27. May 2015, 2 Comments

During our last Know-How sessions I wanted to take a look into the new version of Glass Mapper and how we can possibly auto-generate the models without using TDS. I only had one and half hour of time and was fascinated what I could do in this time - it just worked! This blog post will give you a short overview of what I did and what my thoughts are about this.

I splitted my time into the following goals:

  • Have a short look into Glass Mapper V4
  • Auto-generate models without TDS, is this possible?
  • How to upgrade our existing solutions?

After this short planning, I started directly in my Visual Studio.

Glass Mapper V4

On the first of May, the new version of my favorite ORM was released. The installation over NuGet took me only several seconds, but then I had the first issue: The needed assembly Glass.Mapper.Sc was not referenced. In the first tutorial of the new Glass Mapper website they describe exactly this scenario. To determine the correct Sitecore and MVC version, the assemblies Sitecore.Kernel.dll and System.Web.Mvc.dll must be referenced before installing Glass Mapper.

After the installation, the usage is very similar to the old versions. But Glass Mapper has some important new features:

  • New fluent API for it's configuration
  • New cache (not activated by default!)
  • Better MVC integration

I don't want to repeat all the new features as they are all already described by Mike Edwards.

Model generation

Team Development for Sitecore (TDS) supports auto-generation of the model classes from the data templates within Sitecore. We at Unic don't use TDS, as we have a very nice toolset using other tools. Then I found the sitecore.codegenerator project from Robin Hermanussen on GitHub. The project creates model classes from Sitecore items using T4 templates. As I don't have much experience with this, I just followed the introduction in the README.md. It's very easy: Install, configure, run - and it just works.

I've only tested this with very simple types, I don't know how easy it is with a complex model, but Robin has described how to achieve it. Great job! Does anyone has more experience with this project? Or are there any other projects available doing the same?

Upgrade from V3

Also this seems to be very easy. As I didn't have the time to update one of our complex solutions I just went through the process described on the Glass Mapper website. And also this worked very well. Basically there are only two steps needed:

  • Upgrade NuGet packages and remove unused packages
  • Update the configuration in GlassMapperSc.cs and GlassMapperScCustom.cs

So basically, my favorite ORM it getting even better. Now we can also auto-generate our models without TDS, awesome! I'm very proud to be part of such a great Sitecore community. It's very nice how developer share their work with other developers.

Categories  Modules  Tools Tags  Glass Mapper  Model Generation

2 Comments

  1. DG
    26. August 2015 at 05:16

    Hi,

    I tried following the sitecore.codegenerator tool created by Robin Hermanussen. What did you do with STEP 5?

    In GlassGenerator.tt, change the following code so the path references your serialized data: Context.Host.ResolvePath(@"..\Data\serialization\"). The path is relative to the location of the .tt files.

    What is it referring to by the path references your serialized data?

    Thanks.

  2. sumith
    3. June 2016 at 09:04

    The path is relative to the project, you can change it to any folder, in my case.

    var resolver = new TemplatesResolverRainbow(
    Context.Host.ResolvePath(@"..\Data\unicorn\"),
    Paths,
    Database)

Add your comment

Your email address will not be published. Required fields are marked *

*