Hi Petr,
What happens if you had
var result = query.Select(x => new { m = x.MarketFilter.ToList() }).GetResult();
Hi Paul,
although the type is changed from ItemCollection<string> to List<string>, the Exception stays the same.
You probably want to do this instead
var query = _client.Search<Product>().For("product1");
var result = query.Select(x => new { m = x.Markets() }).GetResult();
Markets is an extension that is the opposite of MarketFilter (which means the markets the product is excluded in)
While not specific to the markets example above. If you want to use projections from TypeSearch with a collection property, then you should ensure the property is declared as IEnumerable<T>. I've had allsorts of issues with IList<T> and List<T> where they did not serialize back or caused errors. It only started working for me when I declared the property being indexed as IEnumerable
e.g.
public class MyPage
{
[Searchable]
public IEnumerable<ChildModel> Children => GetChildren();
private List<ChildModel> GetChildren()
{
// Logic here to return a List<ChildModel>
}
}
Thinking out loud but that would be very strange to be honest. Json can't be serialized to a deferred iterator, it has to serialize to a concrete class (in this case, a List, or an array). I have no idea why it has problem deserializing to a List however ...
While not specific to the markets example above. If you want to use projections from TypeSearch with a collection property, then you should ensure the property is declared as IEnumerable<T>. I've had allsorts of issues with IList<T> and List<T> where they did not serialize back or caused errors. It only started working for me when I declared the property being indexed as IEnumerable
That was it! When I changed IList to IEnumerable in my Epi model, it started working. Thanks!
public class Product : ProductContent {
[Display(
Name = "Product type list",
GroupName = GroupNames.MetaData,
Order = 15)]
[BackingType(typeof(PropertyStringList))]
public virtual IEnumerable<String> ProductTypeList { get; set; }
}
Hello,
I'm trying to deserialize an index of our Product object and it crashes on lists. Here is my code:
The thrown exception reads "'To deserialize objects the $type property must be set." There is no $type property in the Index, should I force it somehow?
It's not possible for any list but MarketFilter is a native property so I thought it should work at least with that.
Thanks.
Epi CMS: 11.21.2
Epi commerce: 13.32.1
EPiServer.Find: 13.4.8.0