SaaS CMS has officially launched! Learn more now.

XhtmlString deserialization issue

Vote:
 

Hi 

I am having an issue when calling GetResult from the search query, the XhtmlString element always return null. I have checked data in the Explorer, it's there. 

"Description": {
        "$type": "EPiServer.Core.XhtmlString, EPiServer",
        "AsViewedByAnonymous$$string": "Size: Bath Towel - 70 x 140cm Hand - 45 x 65cm Bath Sheet - 80 x 160cm GSM: 550",
        "___types": [
            "EPiServer.Core.XhtmlString",
            "System.Object",
            "System.Web.IHtmlString",
            "System.Runtime.Serialization.ISerializable",
            "EPiServer.Data.Entity.IReadOnly`1[[EPiServer.Core.XhtmlString, EPiServer, Version=9.6.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]]",
            "EPiServer.Data.Entity.IReadOnly"
        ],
        "IsEmpty$$bool": false,
        "IsModified$$bool": false
    },

I am using the latest EPi find (v11) with EPiCommerce 9.6
#143997
Feb 04, 2016 11:49
Vote:
 

Hi!

Are you using .AsViewedByAnonymous?

Could you post your query?

#143999
Feb 04, 2016 12:20
Vote:
 
public class FindProduct
    {
        [Id]
        public string IndexId { get; set; }
        public string Code { get; set; }
        public int Id { get; set; }
        public string DisplayName { get; set; }
        public string Language { get; set; }

        public string DefaultImageUrl { get; set; }

        public XhtmlString Description { get; set; }
    }
        public SearchResults<FindProduct> SearchProductsByStyle(ProductBase productBase, bool selfIncluded = false)
        {
            var query = SearchClient.Instance.Search<FindProduct>()
                .Filter(x => x.StyleCode.Exists())
                .Filter(x => x.StyleCode.MatchCaseInsensitive(productBase.StyleCode))
                .Filter(x => x.Language.Exists())
                .Filter(x => x.Language.MatchCaseInsensitive(productBase.Language.Name));

            if (!selfIncluded)
            {
                query
                    .Filter(x => x.Code.Exists())
                    .Filter(x => !x.Code.Match(productBase.Code));
            }
            return query.GetResult();
            //.StaticallyCacheFor(TimeSpan.FromMinutes(5))
        }
#144001
Feb 04, 2016 12:26
Vote:
 

For the time being, I have to change my poco object "Description" type to string, and convert xhtmlstring to html encoded string before assign to description. 

EPi find seems not working well with complex object  :p

#144010
Feb 04, 2016 13:21
Vote:
 

XhtmlString is a complex property type, which is usually fetched when using GetContentResult - which fetches the content from the database.
If possible, I would suggest you change your property type to a string.

By the way, I don't think you need all those .Exists filters. The Match/MatchCaseInsensitive will take care of that anyway - even if the value is null.

#144011
Feb 04, 2016 13:25
Vote:
 

Hi Per

Thanks for your prompt reply and code review :)

As I said, I had switched to string already. Are there any other speicial complex types not supported by EPi find?

#144012
Feb 04, 2016 13:38
Vote:
 

Well, the XhtmlString is a bit special, as it is built up by fragments. Some of these might not be visible to certain users and some might be references to blocks or media data. Because of this the value that resides in the Find index is a simple serialized value, and the common usage would be to either project the value using .Select or to fetch the content using GetContentResult.

As for other types... I suppose you would get the same problem had you added a property of type ContentArea to your poco object

#144015
Feb 04, 2016 13:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.