AI OnAI Off
What's behind the `Document` class, what does it inherit or derive from and what properties does it have?
I'm specifically interested in knowing how you set up the Categories property.
Hi Eric
sorry should have specified that, its just extendeds MediaData
public class Document : MediaData, IHasFileSize
{
[Required]
[Display(GroupName = PropertyGroupNames.Content, Order = 10)]
public virtual string Title { get; set; }
[Display(GroupName = PropertyGroupNames.Content, Order = 20)]
public virtual string Description { get; set; }
[CultureSpecific]
[UIHint(UIHint.Image)]
[AllowedTypes(typeof(ImageFile))]
[Display(GroupName = PropertyGroupNames.Content, Order = 30)]
public virtual ContentReference Image { get; set; }
[Display(GroupName = PropertyGroupNames.Content, Order = 40)]
public virtual bool ExcludeFromSearchResults { get; set; }
[Editable(false)]
[Display(GroupName = PropertyGroupNames.Content, Order = 50)]
public virtual string Extension { get; set; }
[Editable(false)]
[Display(GroupName = PropertyGroupNames.Content, Order = 60)]
public virtual string FileSize { get; set; }
[UIHint("DateOnly")]
[Display(GroupName = PropertyGroupNames.Content, Order = 70)]
public virtual DateTime? FileDate { get; set; }
[Display(GroupName = PropertyGroupNames.Content, Order = 80)]
public virtual string ReferenceId { get; set; }
public virtual int ViewCount => this.ViewCount();
}
and the DocumentResult class is just a simple POCO with some attributes
[Serializable]
public class DocumentResult
{
[StringLength(150)]
public string Title { get; set; }
[StringLength(5)]
public string Extension { get; set; }
[StringLength(15)]
public string FileSize { get; set; }
public DateTime? FileDate { get; set; }
[StringLength(150)]
public string Reference { get; set; }
[StringLength(250)]
public string Url { get; set; }
public CategoryList Categories { get; set; }
public int ContentId { get; set; }
public int ViewCount { get; set; }
}
I would assume you cannot use CategoryList that way. It inherits both IList and IReadOnly where the latter should make the instance immutable.
Instead try to set up your Categories property like this
[Serializable]
public class DocumentResult
{
// ...
public List<int> Categories { get; set; } // this
// ...
}
I am trying to do the following:
this will work fine if I omit the Categories property, but if its included I always get the error:
EPiServer.Find.ProjectionException: To deserialize objects the $type property must be set.
dont really understand why this is happening, I cant be the only person wanting the categories to come out in a search result?