Nested queries: Filter number of nested objects returned from FIND

Vote:
 

Hi!

I was wondering if it possible to filter the number of nested objects that FIND returns in a filtered nested query? Consider the following:

public class Team 
{
 public Team(string name)
 { 
  TeamName = name; 
  Players = new List();
 }
 public string TeamName { get; set; }
 public List Players { get; set; }
}
 
public class Player
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public int Salary { get; set; }
}

result = client.Search()
 .Filter(x => x.Players, p => p.FirstName.Match("player1") & 
    p.LastName.Match("Ronaldo"))
 .GetResult();


Data

Team 1 contains player1 (name = player1)and player2 (name = player2)
Team 2 contains player3  (name = player3) and player4 (name = player4) 

I would like to achive a search result from find that contains
Team1 with Players only containing the object player1. Is it possible? Now it seems like FIND returns Team 1 with both player1 and player2.

/Magnus 

#144802
Feb 19, 2016 8:40
Vote:
 

i am in the same situation. have you sorted it out?

/yasir

#186743
Jan 03, 2018 15:51
Vote:
 
Can you try MatchContained and see if that returns what you need?

var
result = client.Search<Team>() .Filter(x => x.Players.MatchContained( p => p.FirstName, "Ronaldo"));

If not, how about using Projections and creating an anonymous object of what you need?

https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/9/DotNET-Client-API/Searching/Projections/

#187191
Jan 15, 2018 20:07
* 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.