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
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.
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
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.