Sitecore, wrong type of inherited template field created by TDS

671 views Asked by At

I have a problem with template inheritance:

I have base template (let say Parent) which contains the following field:

  • Theme (Droplist with query specified)

And template (Child) derived from it.

The issue is that once I inherited Parent, and generated model for it with TDS, I got:

public virtual string Theme {get; set;}

But expected to get Guid class. Once I swithced Theme field to type Multilist I got:

public virtual IEnumerable<Guid> Themes {get; set;}

Which has Guid type in it...

How can I tell to TDS(GlassMapper) to have Guid instead of string?

2

There are 2 answers

0
Nicolai On BEST ANSWER

Ok, finally, I found my mistake while writing this question... I used wrong type for Theme:

should use Droplink instead of Droplist.

0
jammykam On

You've already figured out that you need to use a DropLink field type (which stores a guiGUID) instead of DropList (which just stores the value).

Instead of returning the GUID and then looking up the item again in Sitecore to then retrieve the values, you can have the TDS CodeGen templates return the linked item type instead by setting the object type in the Custom Data property field.

TDS Codegen

There are 2 main settings of interest:

  • type : For single linked items, e.g. DropLink. Generated code will output:

    public virtual AssetLibrary.LookupValue MyFieldName { get; set; }

  • generic : For multiple linked items, e.g. MultiList field

    public virtual IEnumerable<AssetLibrary.LookupValue> MyFieldName { get; set; }

Since most of the time you want a guid to resolve to a specific type, this saves some boilerplate code to lookup linked items and Glass will automatically resolve to the linked item.