TDS Code Generation and Glass Mapper

955 Views Asked by At

Trying to figure out if this is worth chasing:

Im using TDS to automatically generate my models. If I use the Hedgehog .tt files, it creates a generic collection of child items for each item. I would like to be able to access these child items as strongly typed POCOs. The code generation creates all types as partial, so I make another partial version of my class, and create the stronly typed fields. If I regenerate my models, I do not lose this strongly typed partial class.

Example:

Here is the class that TDS automatically generates:

[SitecoreType(TemplateId=SiteHeaderConstants.TemplateIdString)] //, Cachable = true
public partial class SiteHeader  : IBaseGlassItem, ISiteHeader 
{   
    #region interface members

    public ID ID { get; set; }
    public ID TemplateID { get; set; }
    public Language Language { get; }
    public int Version { get; }
    public IBaseGlassItem Parent { get; }
    public IEnumerable<IBaseGlassItem> Children { get; }
    public string Name { get; }

    #endregion
}

My new partial class with my strongly typed child items:

public partial class SiteHeader
{
    [SitecoreQuery("./*[@@templateid='" + HeaderUtilityNavigationBarConstants.TemplateIdString + "']", IsRelative = true)]
    public IEnumerable<HeaderUtilityNavigationBar> HeaderUtilityNavigationBars { get; }

    public HeaderUtilityNavigationBar GetUtilityNavigationBar()
    {
        return HeaderUtilityNavigationBars.FirstOrDefault();
    }

}

Whats bothering me is that my class now has a generic collection of child items, and a separate collection my strongly typed items, some of which are the same items. Is this going to hit the database twice? hurting performance?

My other option is to just ditch the auto code generation and create the classes myself and I can type them however I want.

0

There are 0 best solutions below