Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Projections on complex objects

Vote:
 

Hi,

We index nested complex objects and filter on fields in the nested classes using the Nested2Find extension. 

e.g.

var usa = new Country
{
States = new List
{
new State
{
Name = "NY",
Towns = new List
{
new Town {Population = 10},
new Town {Population = 20}
}
},
new State
{
Name = "CA",
Towns = new List
{
new Town {Population = 100},
new Town {Population = 200}
}
}
}
};


In the above example the filtering is on the population field and I would like to return only the lists that satisfy the conditions of the filter.

I'm aware that it is not possible to project to complex objects, but is there a way to create a projection of some sort so that the entire result doesn't get transferred over the wire?

e.g. if my filter is "population >= 200", then only the state, "CA" should be transferred over the wire with town where the population is 200.

Thanks

#122797
Jun 14, 2015 17:45
Vote:
 

You can project complex objects but the problem you have is that you only want to project a specific item in a list of complex objects that depend on a specific filter match.

For example you can use:

.Select(x => x.Country.States)

As you are interested in the Town matching you should 'flip' your item and index:

Town: {
Country: "USA",
State: "CA",
Polulation: 200
}

/Henrik

#123069
Jun 24, 2015 11:59
* 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.