Previous Lecture Complete and continue  

  Your First Model

Creating your first model is easy because Glass.Mapper.Sc allows you to use plain old C# objects. The class below demonstrates a model that maps two fields (Title and Logo) and single piece of item information (Url).

When creating models you are not limited to only having string properties. Your models can return standard .Net types such as DateTime, Int, Float, Guid, etc.

Glass.Mapper.Sc also supplies custom .NET types for more complex fields such as links and images. In the above model you can see that we have used the Image type which is a custom type for mapping Images from Sitecore.

After creating the class you can use one of the Glass.Mapper.Sc services to retrieve an item from the Sitecore database and map it directly to the model:

Interfaces or Classes

When creating your models you can choose to either create models using interfaces or classes. The models below both map the same data:

Which you decided to work with is entirely up to you. Additionally a single solution can contain a mixture of interfaces and classes you don't have to stick to one or the other.