0

I'm trying to get item using GlassMapper as follow:

var myCustomObj=SitecoreContext.GetItem<IMy_Custom_Type>(itemId);

But myCustomObj is always null.

When I try to get the item as IGlass_Base object, it works:

var myCustomObj=SitecoreContext.GetItem<IGlass_Base>(itemId);

Edited: Here is how the IMy_Custom_Type looks:

    /// <summary>
    /// IMy_Custom_Type Interface
    /// <para></para>
    /// <para>Path: /sitecore/templates/User Defined/###/Pages/My Custom Type</para>    
    /// <para>ID: dfacd744-0cf8-4917-922c-4baeb07dfe35</para>   
    /// </summary>
    [SitecoreType(TemplateId=IMy_Custom_TypeConstants.TemplateIdString, AutoMap = true )] //, Cachable = true
    public partial interface IMy_Custom_Type : IGlassBase , global::SC.Global.Models.TemplateModels.Base_Templates.IMetadata, global::SC.Global.Models.TemplateModels.Base_Templates.IBase_Background_Image
    {
        /// <summary>
        /// The My Custom field.
        /// <para></para>
        /// <para>Field Type: Multilist</para>      
        /// <para>Field ID: 43388fa5-a02a-425d-ae31-d94a12860748</para>
        /// <para>Custom Data: </para>
        /// </summary>
        [SitecoreField(IMy_Custom_TypeConstants.MyCustomFieldName)]
        IEnumerable<Guid> My_Custom_Field  {get; set;}
        :
        :
        // Few more fields          

    }
Vikram
  • 675
  • 6
  • 25

1 Answers1

0

Create Class called My_Custom_Type implement your interface IMy_Custom_Type, and add all the properties from other interfaces to this class:

public class My_Custom_Type : IMy_Custom_Type 
{
// IMy_Custom_Type  properties
// IGlassBase  properties
// IMetadata properties
// IBase_Background_Image properties
}  

then try to cast your object like this :

var myCustomObj=SitecoreContext.GetItem<My_Custom_Type>(itemId); 
Ayman Barhoum
  • 1,255
  • 1
  • 16
  • 31
  • 1
    Looks like they are using TDS generated Glass models, so the concrete implementation would also be created (by default). But interfaces should also work, and it's often preferable to code against interfaces. – jammykam Jul 04 '16 at 21:51
  • We have implementation of the interface (auto generated via TDS). – Vikram Jul 05 '16 at 10:41