So I have a glassMapped item with an image.
[SitecoreType(TemplateId = TemplateIdConstants.NationalChain, EnforceTemplate = SitecoreEnforceTemplate.Template)]
public interface IChain : IGlassBase
{
[SitecoreField("Logo")]
Image Logo { get; set; }
}
Witch I then try to set:
using (new SecurityDisabler())
using (var db = new SitecoreContext(Sitecore.Context.Database))
{
var item = db.Create<IChain, IGlassBase>(parent, model.Name);
item.Logo = new Image { MediaId = image.ID.ToGuid() };
db.Save(item);
}
This does not work, so I'm looking for the correct way to do this.
Edit, I found one way that works..although I'm not happy with it. I added the following to the interface:
[SitecoreField("Logo")]
string LogoString { get; set; }
I then set the raw value like this:
item.LogoString = "<image mediaid=\"{" + image.ID.ToGuid() + "}\" />";
Is there any better way of doing this?
The following gives a strange result. Image is set while Logo is not set.
[SitecoreType(TemplateId = TemplateIdConstants.NationalChain, EnforceTemplate = SitecoreEnforceTemplate.Template)]
public interface IChain : IGlassBase
{
[SitecoreField("Logo")]
Image Logo { get; set; }
[SitecoreField("Image")]
Image Image { get; set; }
}
item.Image = new Image { MediaId = image.ID.ToGuid() };
item.Logo = new Image { MediaId = image.ID.ToGuid() };
What am I missing?