Is there no standard way to incorporate/ consider a template's standard values when creating a Glassmapper model programmatically? This is all I can find online, but it seems that you have to rename an object just to consider standard values:
When you create the item directly from the model GlassMapper has no way of knowing if the values of the item's properties are to be overwritten by the standard values or if you intended them to be null/empty.
What you want is to first create the item by specifying a parent and a name for the new item.
var itemName = "My new item"; var item = SitecoreContext.Create<IItem, IParentItem>(parent, itemName);
The model of the new item is the first type parameter. The template for the new item is also inferred from this type parameter (
IItem in this case) assuming it has been mapped correctly specifying its template ID (or branch ID) - otherwise you will get an exception.
This new item will now have any standard values set and you can change any values as you please and then save those changes.
item.SomeProperty = "Some value"; SitecoreContext.Save(item);