One of the issues I came across was that when it creates properties for Sitecore link and list fields like DropLink and TreeListEx; it uses GUIDs rather than the entity in question. So how do you get the code generation templates to link to the entity rather than to a GUID?
There is a really simple fix that involves 4 steps.
Let's assume that you have an entity called Product Filter which has a TreeListEx field, which references a list of Brand items.
- In the Sitecore core database navigate to the Field Types folder under system and create a copy of the TreeListEx field naming it something like Brand TreeListEx.
N.B. I also create a new folder to hold all my Entity Types so that they are easy to find when editing a template:
- In the template that uses the field; change the type to be Brand TreeListEx (or whatever you called it).
- In Visual Studio navigate to the TDS project that contains the code generation templates.
N.B. This is probably your Sitecore templates project.
Open up the code generation template for the glass items - in my code this was called glassv3item.tt. Scroll down the script until you find the following method:
public static string GetGlassFieldType(SitecoreField field)
Locate the switch statement add the following on a new line:case "brand treelistex": return "IEnumerable<Brand>";
N.B. The text in the case statement must be lowercase and must exactly match the name of the newly created field in the core database.
N.B Always use IEnumerable for collections.
N.B. For a single item reference field like a DropLink; change the return part to be something like:return "Brand";
- Now synchronize the Sitecore items project so that the Sitecore Glass code generation is redone, and you should then be good to go.
No comments:
Post a Comment