Projections on a nested collection

Vote:
 

Hi!

I have a collection of products and by convention we've added the variants as a property so they are indexed together.
What I'd like to do is project over the results and get the cheapest variant in order to retreive some data to be displayed. This prevents me from loading all variants when the search results.

Is it possible, when projecting, to filter a nested collection?

Example:

Client.Search()
  .Filter(x => x.Code.Match("8801141522433"))  
.FilterPriceAvailableForCurrentUser()
  .Select(p => new
  {
    Code = p.Code,
    SpecificationsList = p.ProductVariations.FirstOrDefault(v => v.Code == p.CheapestVariationCode).Specifications   })
.GetResult();

The SpecificationsList is always empty because Find cannot interpret the FirstOrDefault method I guess but I can't Filter there either.

Thanks for helping out!

/Mark

#179533
Edited, Jun 14, 2017 22:49
Vote:
 

Not sure if it's what you need but if in your example the ProductVariations property had been a Dictionary where you can predict the key it will work with Find.

http://www.lindstromhenrik.com/searching-dictionaries-with-episerver-find/

#179534
Jun 14, 2017 23:40
* 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.