private static List<List<ODataExpansionOptions>> GetExpansions(this IEnumerable<SelectItem> selectedItems, HashSet<string> selects, Type parentType)
{
if (selectedItems == null)
return new List<List<ODataExpansionOptions>>();
return selectedItems.OfType<ExpandedNavigationSelectItem>().Aggregate(new List<List<ODataExpansionOptions>>(), (listOfExpansionLists, next) =>
{
string path = next.PathToNavigationProperty.FirstSegment.Identifier;//Only first segment is necessary because of the new syntax $expand=Builder($expand=City) vs $expand=Builder/City
if (!selects.ExpansionIsValid(path))/*If selects are defined then check to make sure the expansion is one of them.*/
return listOfExpansionLists;
The current implementation requires expansions to be included in the selects, unless selects are missing. The OData specification however says that "Expanded navigation properties MUST be returned, even if they are not specified in $select." (see http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#_Toc31361040).
The method below is in the LinqExtensions class.