Try our conversational search powered by Generative AI!

Projecting to a complex type

Vote:
 

Hi,

I would like to project from a nested list to a list of complex classes in Find. The projection code compiles and everything seems to work.

But when I examine the response directly from Find, the entire object is returned from Find instead of the individual fields.

Assuming the Game class gets indexed:

public class Game

{

public string Code;

public List Platforms; //nested

}

public class Platform

{

public int Id;

public string Name;

public decimal Cost;

public DateTime ReleaseDate;

}

I would like to project only the "Code" from Game and the "Id" and "Name" from Platform.

e.g.

var result = client.Search()
.Select(x => new SearchResult { 
Code = x.Code, 
Boxes= x.Platforms.Select(
y => new Box
              {
                Id= y.Id,

                Name = y.Name
               }),

})
.GetResult();

From the documentation its probably a limitation. But does anyone know if the above is possible in another way?

Thanks,

Danie

#172532
Edited, Dec 06, 2016 12:06
Vote:
 

Hi,

You have to create an anonyme object, and then create your object from that when you get the result back. 

#172638
Edited, Dec 06, 2016 23:00
Vote:
 

Hi Jonas,

thanks for your reply.  I've tried using an anonymous type, but the entire Platforms still gets transfered over the wire instead of the individual fields.

e.g. when using anonymous type the request for the projection looks like this:

"fields":["___types","Code$$string","Platforms$$nested"]

Thanks

Danie

#172649
Dec 07, 2016 10:45
* 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.