I am using Sitecore Glass Mapper for a new project I\'m setting up. We are using Sitecore 7.2, latest version of Team Development for Sitecore (TDS) code generation and the
Most of the times it is a language issue. The mapper returns a null object when you do not have versions in the current or given language.
What can be confusing is that Sitecore.Context.Database.GetItem returns an object, even if it does not have a version in the current language. Be sure to check that item.Versions has any.
Some things you may try (this didn't fit in the comments field)
1) Confirm that the related fields in the Sitecore Item object contain values (so Sitecore.Context.Item
for your "c" var and Sitecore.Context.Database.GetItem("path")
for your "d" var)
2) Try to encapsulate the GetItem/GetCurrentItem call in a VersionCountDisabler
, like this:
T01_Homepage model = null;
using (new VersionCountDisabler())
{
var context = new SitecoreContext();
model = context.GetItem<T01_Homepage>("path");
}
// Do you have data in model now?
3) Try to encapsulate the same call with a SecurityDisabler
. Just to confirm it's not a security issue.
4) If you still don't know what it is, please update your question with some (simplified) code for your model.
Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.
I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.