1

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.

Christian Hagelid
  • 8,275
  • 4
  • 40
  • 63
Ethan Schofer
  • 1,718
  • 5
  • 26
  • 55
  • The `Parent` and `Children` properties are not generated by the default [CodeGen templates](https://github.com/HedgehogDevelopment/tds-codegen/tree/master/Sitecore.Master/Code%20Generation%20Templates) so yours have most likely been extended. My suggestion would be to remove these and manually add them to the Partial, but autogenerated or manually created is primarily opinion based. – jammykam Jan 25 '16 at 22:19
  • Manually created models certainly are the most flexible. I like using the Glass Mapper fluent API then so I can build unit tests without needing any Sitecore config dependencies. – Jim Noellsch Jan 26 '16 at 02:52

0 Answers0