public override void Apply(PropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute, ODataConventionModelBuilder model) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (!edmProperty.AddedExplicitly) { ExpandAttribute expandAttribute = attribute as ExpandAttribute; ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.ExpandConfigurations.Count == 0) { querySettings.CopyExpandConfigurations(expandAttribute.ExpandConfigurations); } else { foreach (var property in expandAttribute.ExpandConfigurations.Keys) { querySettings.ExpandConfigurations[property] = expandAttribute.ExpandConfigurations[property]; } } if (expandAttribute.ExpandConfigurations.Count == 0) { querySettings.DefaultExpandType = expandAttribute.DefaultExpandType; querySettings.DefaultMaxDepth = expandAttribute.DefaultMaxDepth ?? ODataValidationSettings.DefaultMaxExpansionDepth; } } }
private static ModelBoundQuerySettings GetMergedPropertyQuerySettings( ModelBoundQuerySettings propertyQuerySettings, ModelBoundQuerySettings propertyTypeQuerySettings) { ModelBoundQuerySettings mergedQuerySettings = new ModelBoundQuerySettings(propertyQuerySettings); if (propertyTypeQuerySettings != null) { if (!mergedQuerySettings.PageSize.HasValue) { mergedQuerySettings.PageSize = propertyTypeQuerySettings.PageSize; } if (mergedQuerySettings.MaxTop == 0 && propertyTypeQuerySettings.MaxTop != 0) { mergedQuerySettings.MaxTop = propertyTypeQuerySettings.MaxTop; } if (!mergedQuerySettings.Countable.HasValue) { mergedQuerySettings.Countable = propertyTypeQuerySettings.Countable; } if (mergedQuerySettings.OrderByConfigurations.Count == 0 && !mergedQuerySettings.DefaultEnableOrderBy.HasValue) { mergedQuerySettings.CopyOrderByConfigurations(propertyTypeQuerySettings.OrderByConfigurations); mergedQuerySettings.DefaultEnableOrderBy = propertyTypeQuerySettings.DefaultEnableOrderBy; } if (mergedQuerySettings.FilterConfigurations.Count == 0 && !mergedQuerySettings.DefaultEnableFilter.HasValue) { mergedQuerySettings.CopyFilterConfigurations(propertyTypeQuerySettings.FilterConfigurations); mergedQuerySettings.DefaultEnableFilter = propertyTypeQuerySettings.DefaultEnableFilter; } if (mergedQuerySettings.SelectConfigurations.Count == 0 && !mergedQuerySettings.DefaultSelectType.HasValue) { mergedQuerySettings.CopySelectConfigurations(propertyTypeQuerySettings.SelectConfigurations); mergedQuerySettings.DefaultSelectType = propertyTypeQuerySettings.DefaultSelectType; } if (mergedQuerySettings.ExpandConfigurations.Count == 0 && !mergedQuerySettings.DefaultExpandType.HasValue) { mergedQuerySettings.CopyExpandConfigurations( propertyTypeQuerySettings.ExpandConfigurations); mergedQuerySettings.DefaultExpandType = propertyTypeQuerySettings.DefaultExpandType; mergedQuerySettings.DefaultMaxDepth = propertyTypeQuerySettings.DefaultMaxDepth; } } return(mergedQuerySettings); }