diff --git a/src/Microsoft.OData.ModelBuilder/Attributes/ExpandAttribute.cs b/src/Microsoft.OData.ModelBuilder/Attributes/ExpandAttribute.cs index f2bb38c..afe3a83 100644 --- a/src/Microsoft.OData.ModelBuilder/Attributes/ExpandAttribute.cs +++ b/src/Microsoft.OData.ModelBuilder/Attributes/ExpandAttribute.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using Microsoft.OData.ModelBuilder.Config; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; namespace Microsoft.OData.ModelBuilder { @@ -12,11 +12,8 @@ namespace Microsoft.OData.ModelBuilder /// correlate to OData's $expand query option settings. /// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true)] - [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", - Justification = "Don't want those argument to be retrievable")] public sealed class ExpandAttribute : Attribute { -#if false private readonly Dictionary _expandConfigurations = new Dictionary(); private SelectExpandType _expandType; private SelectExpandType? _defaultExpandType; @@ -29,7 +26,7 @@ public sealed class ExpandAttribute : Attribute public ExpandAttribute() { _defaultExpandType = SelectExpandType.Allowed; - // _defaultMaxDepth = ODataValidationSettings.DefaultMaxExpansionDepth; + _defaultMaxDepth = QueryConfiguration.DefaultMaxExpansionDepth; } /// @@ -45,7 +42,7 @@ public ExpandAttribute(params string[] properties) _expandConfigurations.Add(property, new ExpandConfiguration { ExpandType = SelectExpandType.Allowed, - MaxDepth = ODataValidationSettings.DefaultMaxExpansionDepth + MaxDepth = QueryConfiguration.DefaultMaxExpansionDepth }); } } @@ -133,6 +130,5 @@ internal int? DefaultMaxDepth _defaultMaxDepth = value; } } -#endif } } diff --git a/src/Microsoft.OData.ModelBuilder/Attributes/FilterCountAttribute.cs b/src/Microsoft.OData.ModelBuilder/Attributes/FilterCountAttribute.cs index 435ae58..9567dae 100644 --- a/src/Microsoft.OData.ModelBuilder/Attributes/FilterCountAttribute.cs +++ b/src/Microsoft.OData.ModelBuilder/Attributes/FilterCountAttribute.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Microsoft.OData.ModelBuilder @@ -13,8 +12,6 @@ namespace Microsoft.OData.ModelBuilder /// correlate to OData's $filter query option settings. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true)] - [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", - Justification = "Don't want those argument to be retrievable")] public sealed class FilterAttribute : Attribute { private bool? _defaultEnableFilter; diff --git a/src/Microsoft.OData.ModelBuilder/Attributes/OrderByAttribute.cs b/src/Microsoft.OData.ModelBuilder/Attributes/OrderByAttribute.cs index 0f8ae77..64e58f2 100644 --- a/src/Microsoft.OData.ModelBuilder/Attributes/OrderByAttribute.cs +++ b/src/Microsoft.OData.ModelBuilder/Attributes/OrderByAttribute.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Microsoft.OData.ModelBuilder @@ -13,8 +12,6 @@ namespace Microsoft.OData.ModelBuilder /// correlate to OData's $orderby query option settings. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true)] - [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", - Justification = "Don't want those argument to be retrievable")] public sealed class OrderByAttribute : Attribute { private bool? _defaultEnableOrderBy; diff --git a/src/Microsoft.OData.ModelBuilder/Attributes/SelectAttribute.cs b/src/Microsoft.OData.ModelBuilder/Attributes/SelectAttribute.cs index dd8f50a..64990db 100644 --- a/src/Microsoft.OData.ModelBuilder/Attributes/SelectAttribute.cs +++ b/src/Microsoft.OData.ModelBuilder/Attributes/SelectAttribute.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Microsoft.OData.ModelBuilder @@ -13,8 +12,6 @@ namespace Microsoft.OData.ModelBuilder /// correlate to OData's $select query option settings. /// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true)] - [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", - Justification = "Don't want those argument to be retrievable")] public sealed class SelectAttribute : Attribute { private readonly Dictionary _selectConfigurations = new Dictionary(); diff --git a/src/Microsoft.OData.ModelBuilder/Config/QueryConfiguration.cs b/src/Microsoft.OData.ModelBuilder/Config/QueryConfiguration.cs new file mode 100644 index 0000000..0bde2db --- /dev/null +++ b/src/Microsoft.OData.ModelBuilder/Config/QueryConfiguration.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.Collections.Generic; + +namespace Microsoft.OData.ModelBuilder.Config +{ + /// + /// Query configuration which contains . + /// + public class QueryConfiguration + { + internal const int DefaultMaxExpansionDepth = 2; + + private ModelBoundQuerySettings _querySettings; + + /// + /// Gets or sets the . + /// + public ModelBoundQuerySettings ModelBoundQuerySettings + { + get + { + return _querySettings; + } + set + { + _querySettings = value; + } + } + + /// + /// Sets the Countable in . + /// + public virtual void SetCount(bool enableCount) + { + GetModelBoundQuerySettingsOrDefault().Countable = enableCount; + } + + /// + /// Sets the MaxTop in . + /// + public virtual void SetMaxTop(int? maxTop) + { + GetModelBoundQuerySettingsOrDefault().MaxTop = maxTop; + } + + /// + /// Sets the PageSize in . + /// + public virtual void SetPageSize(int? pageSize) + { + GetModelBoundQuerySettingsOrDefault().PageSize = pageSize; + } + + /// + /// Sets the ExpandConfigurations in . + /// + public virtual void SetExpand(IEnumerable properties, int? maxDepth, SelectExpandType expandType) + { + GetModelBoundQuerySettingsOrDefault(); + if (properties == null) + { + ModelBoundQuerySettings.DefaultExpandType = expandType; + ModelBoundQuerySettings.DefaultMaxDepth = maxDepth ?? DefaultMaxExpansionDepth; + } + else + { + foreach (var property in properties) + { + ModelBoundQuerySettings.ExpandConfigurations[property] = new ExpandConfiguration + { + ExpandType = expandType, + MaxDepth = maxDepth ?? DefaultMaxExpansionDepth + }; + } + } + } + + /// + /// Sets the SelectConfigurations in . + /// + public virtual void SetSelect(IEnumerable properties, SelectExpandType selectType) + { + GetModelBoundQuerySettingsOrDefault(); + if (properties == null) + { + ModelBoundQuerySettings.DefaultSelectType = selectType; + } + else + { + foreach (var property in properties) + { + ModelBoundQuerySettings.SelectConfigurations[property] = selectType; + } + } + } + + /// + /// Sets the OrderByConfigurations in . + /// + public virtual void SetOrderBy(IEnumerable properties, bool enableOrderBy) + { + GetModelBoundQuerySettingsOrDefault(); + if (properties == null) + { + ModelBoundQuerySettings.DefaultEnableOrderBy = enableOrderBy; + } + else + { + foreach (var property in properties) + { + ModelBoundQuerySettings.OrderByConfigurations[property] = enableOrderBy; + } + } + } + + /// + /// Sets the FilterConfigurations in . + /// + public virtual void SetFilter(IEnumerable properties, bool enableFilter) + { + GetModelBoundQuerySettingsOrDefault(); + if (properties == null) + { + ModelBoundQuerySettings.DefaultEnableFilter = enableFilter; + } + else + { + foreach (var property in properties) + { + ModelBoundQuerySettings.FilterConfigurations[property] = enableFilter; + } + } + } + + /// + /// Gets the or create it depends on the default settings. + /// + internal ModelBoundQuerySettings GetModelBoundQuerySettingsOrDefault() + { + if (_querySettings == null) + { + _querySettings = new ModelBoundQuerySettings(ModelBoundQuerySettings.DefaultModelBoundQuerySettings); + } + + return _querySettings; + } + } +} diff --git a/src/Microsoft.OData.ModelBuilder/Config/QueryableRestrictions.cs b/src/Microsoft.OData.ModelBuilder/Config/QueryableRestrictions.cs index beb1662..7d4ee9a 100644 --- a/src/Microsoft.OData.ModelBuilder/Config/QueryableRestrictions.cs +++ b/src/Microsoft.OData.ModelBuilder/Config/QueryableRestrictions.cs @@ -44,7 +44,7 @@ public QueryableRestrictions(PropertyConfiguration propertyConfiguration) public bool NotFilterable { get; set; } /// - /// Gets or sets whether the property is nonfilterable. default is false. + /// Gets or sets whether the property is non-filterable. default is false. /// public bool NonFilterable { diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmPropertyConvention.cs index 7425063..d1c58a4 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmPropertyConvention.cs @@ -21,7 +21,7 @@ public override void Apply(PropertyConfiguration edmProperty, { throw Error.ArgumentNull("edmProperty"); } - /* + if (!edmProperty.AddedExplicitly) { CountAttribute countAttribute = attribute as CountAttribute; @@ -33,7 +33,7 @@ public override void Apply(PropertyConfiguration edmProperty, { edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault().Countable = true; } - }*/ + } } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmTypeConvention.cs index 6b9ece5..f61147c 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/CountAttributeEdmTypeConvention.cs @@ -34,7 +34,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { CountAttribute countAttribute = attribute as CountAttribute; - /* + if (countAttribute.Disabled) { edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault().Countable = false; @@ -43,7 +43,6 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa { edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault().Countable = true; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmPropertyConvention.cs index d0925e3..31936cf 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmPropertyConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -25,7 +26,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (!edmProperty.AddedExplicitly) { ExpandAttribute expandAttribute = attribute as ExpandAttribute; - /* + ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.ExpandConfigurations.Count == 0) { @@ -43,9 +44,8 @@ public override void Apply(PropertyConfiguration edmProperty, if (expandAttribute.ExpandConfigurations.Count == 0) { querySettings.DefaultExpandType = expandAttribute.DefaultExpandType; - querySettings.DefaultMaxDepth = expandAttribute.DefaultMaxDepth ?? ODataValidationSettings.DefaultMaxExpansionDepth; + querySettings.DefaultMaxDepth = expandAttribute.DefaultMaxDepth ?? QueryConfiguration.DefaultMaxExpansionDepth; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmTypeConvention.cs index 604df8b..cbb17a3 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/ExpandAttributeEdmTypeConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -34,13 +35,12 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { ExpandAttribute expandAttribute = attribute as ExpandAttribute; - /* + ModelBoundQuerySettings querySettings = edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.ExpandConfigurations.Count == 0) { - querySettings.CopyExpandConfigurations( - expandAttribute.ExpandConfigurations); + querySettings.CopyExpandConfigurations(expandAttribute.ExpandConfigurations); } else { @@ -54,9 +54,8 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (expandAttribute.ExpandConfigurations.Count == 0) { querySettings.DefaultExpandType = expandAttribute.DefaultExpandType; - querySettings.DefaultMaxDepth = expandAttribute.DefaultMaxDepth ?? ODataValidationSettings.DefaultMaxExpansionDepth; + querySettings.DefaultMaxDepth = expandAttribute.DefaultMaxDepth ?? QueryConfiguration.DefaultMaxExpansionDepth; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmPropertyConvention.cs index 874bf13..7d135d2 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmPropertyConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -25,7 +26,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (!edmProperty.AddedExplicitly) { FilterAttribute filterAttribute = attribute as FilterAttribute; - /* + ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.FilterConfigurations.Count == 0) { @@ -43,7 +44,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (filterAttribute.FilterConfigurations.Count == 0) { querySettings.DefaultEnableFilter = filterAttribute.DefaultEnableFilter; - }*/ + } } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmTypeConvention.cs index 8a6003c..b08bfc5 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/FilterAttributeEdmTypeConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -34,7 +35,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { FilterAttribute filterAttribute = attribute as FilterAttribute; - /* + ModelBoundQuerySettings querySettings = edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.FilterConfigurations.Count == 0) @@ -55,7 +56,6 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa { querySettings.DefaultEnableFilter = filterAttribute.DefaultEnableFilter; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmPropertyConvention.cs index 18f1be4..aafe26b 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmPropertyConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -25,7 +26,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (!edmProperty.AddedExplicitly) { OrderByAttribute orderByAttribute = attribute as OrderByAttribute; - /* + ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.OrderByConfigurations.Count == 0) @@ -45,7 +46,6 @@ public override void Apply(PropertyConfiguration edmProperty, { querySettings.DefaultEnableOrderBy = orderByAttribute.DefaultEnableOrderBy; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmTypeConvention.cs index 3055891..e18a770 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/OrderByAttributeEdmTypeConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -34,7 +35,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { OrderByAttribute orderByAttribute = attribute as OrderByAttribute; - /* + ModelBoundQuerySettings querySettings = edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.OrderByConfigurations.Count == 0) @@ -56,7 +57,6 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa querySettings.DefaultEnableOrderBy = orderByAttribute.DefaultEnableOrderBy; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmPropertyConvention.cs index 7f9c058..4fd85fb 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmPropertyConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -25,7 +26,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (!edmProperty.AddedExplicitly) { PageAttribute pageAttribute = attribute as PageAttribute; - /* + ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (pageAttribute.MaxTop < 0) { @@ -40,7 +41,6 @@ public override void Apply(PropertyConfiguration edmProperty, { querySettings.PageSize = pageAttribute.PageSize; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmTypeConvention.cs index e92cda0..e6e20aa 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/PageAttributeEdmTypeConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -34,7 +35,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { PageAttribute pageAttribute = attribute as PageAttribute; - /* + ModelBoundQuerySettings querySettings = edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); @@ -51,7 +52,6 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa { querySettings.PageSize = pageAttribute.PageSize; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmPropertyConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmPropertyConvention.cs index 42e289f..58e0951 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmPropertyConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmPropertyConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -25,7 +26,7 @@ public override void Apply(PropertyConfiguration edmProperty, if (!edmProperty.AddedExplicitly) { SelectAttribute selectAttribute = attribute as SelectAttribute; - /* + ModelBoundQuerySettings querySettings = edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.SelectConfigurations.Count == 0) @@ -45,7 +46,6 @@ public override void Apply(PropertyConfiguration edmProperty, { querySettings.DefaultSelectType = selectAttribute.DefaultSelectType; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmTypeConvention.cs b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmTypeConvention.cs index 5eca20e..0273dcd 100644 --- a/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmTypeConvention.cs +++ b/src/Microsoft.OData.ModelBuilder/Conventions/Attributes/SelectAttributeEdmTypeConvention.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder.Conventions.Attributes { @@ -34,7 +35,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa if (!edmTypeConfiguration.AddedExplicitly) { SelectAttribute selectAttribute = attribute as SelectAttribute; - /* + ModelBoundQuerySettings querySettings = edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault(); if (querySettings.SelectConfigurations.Count == 0) @@ -56,7 +57,6 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa querySettings.DefaultSelectType = selectAttribute.DefaultSelectType; } - */ } } } diff --git a/src/Microsoft.OData.ModelBuilder/Helpers/EdmTypeBuilder.cs b/src/Microsoft.OData.ModelBuilder/Helpers/EdmTypeBuilder.cs index f84f931..66f3094 100644 --- a/src/Microsoft.OData.ModelBuilder/Helpers/EdmTypeBuilder.cs +++ b/src/Microsoft.OData.ModelBuilder/Helpers/EdmTypeBuilder.cs @@ -160,13 +160,13 @@ private void CreateEdmTypeHeader(IEdmTypeConfiguration config) if (structuredType != null && structuralTypeConfiguration != null && !_structuredTypeQuerySettings.ContainsKey(structuredType)) { - //ModelBoundQuerySettings querySettings = - // structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings; - //if (querySettings != null) - //{ - // _structuredTypeQuerySettings.Add(structuredType, - // structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings); - //} + ModelBoundQuerySettings querySettings = + structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings; + if (querySettings != null) + { + _structuredTypeQuerySettings.Add(structuredType, + structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings); + } } } @@ -273,11 +273,11 @@ private void CreateNavigationProperty(StructuralTypeConfiguration config) { _propertiesRestrictions[edmProperty] = new QueryableRestrictions(prop); } - /* + if (prop.QueryConfiguration.ModelBoundQuerySettings != null) { _propertiesQuerySettings.Add(edmProperty, prop.QueryConfiguration.ModelBoundQuerySettings); - }*/ + } } } } @@ -342,7 +342,6 @@ private static IEdmTypeReference AddLengthConfigInPrimitiveTypeReference( return primitiveTypeReference; } - [SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Class coupling acceptable")] private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConfiguration config) { foreach (PropertyConfiguration property in config.Properties) @@ -433,10 +432,10 @@ private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConf _propertiesRestrictions[edmProperty] = new QueryableRestrictions(property); } - //if (property.QueryConfiguration.ModelBoundQuerySettings != null) - //{ - // _propertiesQuerySettings.Add(edmProperty, property.QueryConfiguration.ModelBoundQuerySettings); - //} + if (property.QueryConfiguration.ModelBoundQuerySettings != null) + { + _propertiesQuerySettings.Add(edmProperty, property.QueryConfiguration.ModelBoundQuerySettings); + } } } } diff --git a/src/Microsoft.OData.ModelBuilder/Microsoft.OData.ModelBuilder.xml b/src/Microsoft.OData.ModelBuilder/Microsoft.OData.ModelBuilder.xml index 194b962..1e96061 100644 --- a/src/Microsoft.OData.ModelBuilder/Microsoft.OData.ModelBuilder.xml +++ b/src/Microsoft.OData.ModelBuilder/Microsoft.OData.ModelBuilder.xml @@ -268,6 +268,32 @@ correlate to OData's $expand query option settings. + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class + with the name of allowed expand properties. + + + + + Gets or sets the of navigation properties. + + + + + Gets or sets the of navigation properties. + + + + + Gets or sets the maximum expand depth of navigation properties. + + Represents an that can be placed on a class or property @@ -928,7 +954,7 @@ - Gets or sets whether the property is nonfilterable. default is false. + Gets or sets whether the property is non-filterable. default is false. @@ -966,6 +992,56 @@ If set to true then automatic expand will be disabled if there is a $select specify by client. + + + Query configuration which contains . + + + + + Gets or sets the . + + + + + Sets the Countable in . + + + + + Sets the MaxTop in . + + + + + Sets the PageSize in . + + + + + Sets the ExpandConfigurations in . + + + + + Sets the SelectConfigurations in . + + + + + Sets the OrderByConfigurations in . + + + + + Sets the FilterConfigurations in . + + + + + Gets the or create it depends on the default settings. + + Represents the configuration for the binding path that can be built using . @@ -3567,7 +3643,7 @@ Initializes a new instance of the class. - The name of the property. + The property info. The declaring EDM type of the property. @@ -3657,6 +3733,11 @@ Get or sets order in "order by" expression. + + + Gets or sets the . + + Sets the property as not filterable. @@ -3717,6 +3798,129 @@ Sets the property as countable. + + + Sets this property is countable. + + + + + Sets whether this property is countable. + + + + + Sets all properties of this property is sortable. + + + + + Sets sortable properties of this property. + + + + + Sets whether all properties of this property is sortable. + + + + + Sets sortable properties depends on boolean of this property. + + + + + Sets all properties of this property is filterable. + + + + + Sets filterable properties of this property. + + + + + Sets whether all properties of this property is filterable. + + + + + Sets filterable properties depends on boolean of this property. + + + + + Sets selectable properties depends on of this property. + + + + + Sets selectable properties of this property. + + + + + Sets of all properties of this property is selectable. + + + + + Sets all properties of this property is selectable. + + + + + Sets the max value of $top of this property that a client can request + and the maximum number of query results of this property to return. + + + + + Sets this property enable paging. + + + + + Sets the maximum depth of expand result, + expandable properties and their of this navigation property. + + + + + Sets the expandable properties of this navigation property. + + + + + Sets the maximum depth of expand result, + expandable properties of this navigation property. + + + + + Sets the expandable properties and their of this navigation property. + + + + + Sets of all properties with maximum depth of expand result. + + + + + Sets all properties expandable with maximum depth of expand result. + + + + + Sets of all properties. + + + + + Sets all properties expandable. + + Extensions method for . @@ -4932,6 +5136,11 @@ Gets the collection of of this entity type. + + + Gets or sets the . + + Gets or sets a value that is true if the type's name or namespace was set by the user; false if it was inferred through conventions. @@ -5360,6 +5569,129 @@ Function(t) t.MyProperty. A configuration object that can be used to further configure the relationship. + + + Sets this property is countable of this structural type. + + + + + Sets whether this property is countable of this structural type. + + + + + Sets sortable properties depends on boolean value of this structural type. + + + + + Sets sortable properties of this structural type. + + + + + Sets whether all properties of this structural type is sortable. + + + + + Sets all properties of this structural type is sortable. + + + + + Sets filterable properties depends on boolean value of this structural type. + + + + + Sets filterable properties of this structural type. + + + + + Sets whether all properties of this structural type is filterable. + + + + + Sets all properties of this structural type is filterable. + + + + + Sets selectable properties depends on of this structural type. + + + + + Sets selectable properties of this structural type. + + + + + Sets of all properties of this structural type is selectable. + + + + + Sets all properties of this structural type is selectable. + + + + + Sets the max value of $top of this structural type that a client can request + and the maximum number of query results of this entity type to return. + + + + + Sets the properties of this structural type enable paging. + + + + + Sets the maximum depth of expand result, + expandable properties and their of this structural type. + + + + + Sets the expandable properties of this structural type. + + + + + Sets the maximum depth of expand result, + expandable properties of this structural type. + + + + + Sets the expandable properties and their of this structural type. + + + + + Sets of all properties with maximum depth of expand result of this structural type. + + + + + Sets all properties expandable with maximum depth of expand result of this structural type. + + + + + Sets of all properties of this structural type. + + + + + Sets all properties expandable of this structural type. + + Enumerates the navigation type can apply on navigation restrictions. diff --git a/src/Microsoft.OData.ModelBuilder/Property/PropertyConfiguration.cs b/src/Microsoft.OData.ModelBuilder/Property/PropertyConfiguration.cs index 514fbe5..5e0d140 100644 --- a/src/Microsoft.OData.ModelBuilder/Property/PropertyConfiguration.cs +++ b/src/Microsoft.OData.ModelBuilder/Property/PropertyConfiguration.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using Microsoft.OData.ModelBuilder.Config; using System; using System.Reflection; @@ -16,7 +17,7 @@ public abstract class PropertyConfiguration /// /// Initializes a new instance of the class. /// - /// The name of the property. + /// The property info. /// The declaring EDM type of the property. protected PropertyConfiguration(PropertyInfo property, StructuralTypeConfiguration declaringType) { @@ -26,6 +27,7 @@ protected PropertyConfiguration(PropertyInfo property, StructuralTypeConfigurati AddedExplicitly = true; _name = property.Name; + QueryConfiguration = new QueryConfiguration(); } /// @@ -51,12 +53,12 @@ public string Name /// /// Gets the declaring type. /// - public StructuralTypeConfiguration DeclaringType { get; private set; } + public StructuralTypeConfiguration DeclaringType { get; } /// /// Gets the mapping CLR . /// - public PropertyInfo PropertyInfo { get; private set; } + public PropertyInfo PropertyInfo { get; } /// /// Gets the CLR of the property. @@ -141,6 +143,11 @@ public bool Unsortable /// public int Order { get; set; } + /// + /// Gets or sets the . + /// + public QueryConfiguration QueryConfiguration { get; set; } + /// /// Sets the property as not filterable. /// @@ -248,5 +255,220 @@ public PropertyConfiguration IsCountable() NotCountable = false; return this; } + + + /// + /// Sets this property is countable. + /// + public PropertyConfiguration Count() + { + return Count(true); + } + + /// + /// Sets whether this property is countable. + /// + public PropertyConfiguration Count(bool enabled) + { + QueryConfiguration.SetCount(enabled); + return this; + } + + /// + /// Sets all properties of this property is sortable. + /// + public PropertyConfiguration OrderBy() + { + return OrderBy(true, null); + } + + /// + /// Sets sortable properties of this property. + /// + public PropertyConfiguration OrderBy(params string[] properties) + { + return OrderBy(true, properties); + } + + /// + /// Sets whether all properties of this property is sortable. + /// + public PropertyConfiguration OrderBy(bool enabled) + { + return OrderBy(enabled, null); + } + + /// + /// Sets sortable properties depends on boolean of this property. + /// + public PropertyConfiguration OrderBy(bool enabled, params string[] properties) + { + QueryConfiguration.SetOrderBy(properties, enabled); + return this; + } + + /// + /// Sets all properties of this property is filterable. + /// + public PropertyConfiguration Filter() + { + return Filter(true, null); + } + + /// + /// Sets filterable properties of this property. + /// + public PropertyConfiguration Filter(params string[] properties) + { + return Filter(true, properties); + } + + /// + /// Sets whether all properties of this property is filterable. + /// + public PropertyConfiguration Filter(bool enabled) + { + return Filter(enabled, null); + } + + /// + /// Sets filterable properties depends on boolean of this property. + /// + public PropertyConfiguration Filter(bool enabled, params string[] properties) + { + QueryConfiguration.SetFilter(properties, enabled); + return this; + } + + /// + /// Sets selectable properties depends on of this property. + /// + public PropertyConfiguration Select(SelectExpandType selectType, params string[] properties) + { + QueryConfiguration.SetSelect(properties, selectType); + return this; + } + + /// + /// Sets selectable properties of this property. + /// + public PropertyConfiguration Select(params string[] properties) + { + QueryConfiguration.SetSelect(properties, SelectExpandType.Allowed); + return this; + } + + /// + /// Sets of all properties of this property is selectable. + /// + public PropertyConfiguration Select(SelectExpandType selectType) + { + QueryConfiguration.SetSelect(null, selectType); + return this; + } + + /// + /// Sets all properties of this property is selectable. + /// + public PropertyConfiguration Select() + { + QueryConfiguration.SetSelect(null, SelectExpandType.Allowed); + return this; + } + + /// + /// Sets the max value of $top of this property that a client can request + /// and the maximum number of query results of this property to return. + /// + public PropertyConfiguration Page(int? maxTopValue, int? pageSizeValue) + { + QueryConfiguration.SetMaxTop(maxTopValue); + QueryConfiguration.SetPageSize(pageSizeValue); + return this; + } + + /// + /// Sets this property enable paging. + /// + public PropertyConfiguration Page() + { + QueryConfiguration.SetMaxTop(null); + QueryConfiguration.SetPageSize(null); + return this; + } + + /// + /// Sets the maximum depth of expand result, + /// expandable properties and their of this navigation property. + /// + public PropertyConfiguration Expand(int maxDepth, SelectExpandType expandType, params string[] properties) + { + QueryConfiguration.SetExpand(properties, maxDepth, expandType); + return this; + } + + /// + /// Sets the expandable properties of this navigation property. + /// + public PropertyConfiguration Expand(params string[] properties) + { + QueryConfiguration.SetExpand(properties, null, SelectExpandType.Allowed); + return this; + } + + /// + /// Sets the maximum depth of expand result, + /// expandable properties of this navigation property. + /// + public PropertyConfiguration Expand(int maxDepth, params string[] properties) + { + QueryConfiguration.SetExpand(properties, maxDepth, SelectExpandType.Allowed); + return this; + } + + /// + /// Sets the expandable properties and their of this navigation property. + /// + public PropertyConfiguration Expand(SelectExpandType expandType, params string[] properties) + { + QueryConfiguration.SetExpand(properties, null, expandType); + return this; + } + + /// + /// Sets of all properties with maximum depth of expand result. + /// + public PropertyConfiguration Expand(SelectExpandType expandType, int maxDepth) + { + QueryConfiguration.SetExpand(null, maxDepth, expandType); + return this; + } + + /// + /// Sets all properties expandable with maximum depth of expand result. + /// + public PropertyConfiguration Expand(int maxDepth) + { + QueryConfiguration.SetExpand(null, maxDepth, SelectExpandType.Allowed); + return this; + } + + /// + /// Sets of all properties. + /// + public PropertyConfiguration Expand(SelectExpandType expandType) + { + QueryConfiguration.SetExpand(null, null, expandType); + return this; + } + + /// + /// Sets all properties expandable. + /// + public PropertyConfiguration Expand() + { + QueryConfiguration.SetExpand(null, null, SelectExpandType.Allowed); + return this; + } } } diff --git a/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfiguration.cs b/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfiguration.cs index 04961bc..98657aa 100644 --- a/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfiguration.cs +++ b/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfiguration.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Reflection; using Microsoft.OData.Edm; +using Microsoft.OData.ModelBuilder.Config; namespace Microsoft.OData.ModelBuilder { @@ -29,6 +30,7 @@ protected StructuralTypeConfiguration() { ExplicitProperties = new Dictionary(); RemovedProperties = new List(); + QueryConfiguration = new QueryConfiguration(); } /// @@ -177,6 +179,11 @@ public virtual IEnumerable NavigationProperties } } + /// + /// Gets or sets the . + /// + public QueryConfiguration QueryConfiguration { get; set; } + /// /// Gets or sets a value that is true if the type's name or namespace was set by the user; false if it was inferred through conventions. /// diff --git a/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfigurationOfTStructuralType.cs b/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfigurationOfTStructuralType.cs index 63dd14e..9923705 100644 --- a/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfigurationOfTStructuralType.cs +++ b/src/Microsoft.OData.ModelBuilder/Types/StructuralTypeConfigurationOfTStructuralType.cs @@ -617,6 +617,253 @@ public NavigationPropertyConfiguration ContainsRequired( return GetOrCreateContainedNavigationProperty(navigationPropertyExpression, EdmMultiplicity.One); } + + /// + /// Sets this property is countable of this structural type. + /// + public StructuralTypeConfiguration Count() + { + Configuration.QueryConfiguration.SetCount(true); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets whether this property is countable of this structural type. + /// + public StructuralTypeConfiguration Count(bool enabled) + { + Configuration.QueryConfiguration.SetCount(enabled); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets sortable properties depends on boolean value of this structural type. + /// + public StructuralTypeConfiguration OrderBy(bool enabled, params string[] properties) + { + Configuration.QueryConfiguration.SetOrderBy(properties, enabled); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets sortable properties of this structural type. + /// + public StructuralTypeConfiguration OrderBy(params string[] properties) + { + Configuration.QueryConfiguration.SetOrderBy(properties, true); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets whether all properties of this structural type is sortable. + /// + public StructuralTypeConfiguration OrderBy(bool enabled) + { + Configuration.QueryConfiguration.SetOrderBy(null, enabled); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets all properties of this structural type is sortable. + /// + public StructuralTypeConfiguration OrderBy() + { + Configuration.QueryConfiguration.SetOrderBy(null, true); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets filterable properties depends on boolean value of this structural type. + /// + public StructuralTypeConfiguration Filter(bool enabled, params string[] properties) + { + Configuration.QueryConfiguration.SetFilter(properties, enabled); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets filterable properties of this structural type. + /// + public StructuralTypeConfiguration Filter(params string[] properties) + { + Configuration.QueryConfiguration.SetFilter(properties, true); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets whether all properties of this structural type is filterable. + /// + public StructuralTypeConfiguration Filter(bool enabled) + { + Configuration.QueryConfiguration.SetFilter(null, enabled); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets all properties of this structural type is filterable. + /// + public StructuralTypeConfiguration Filter() + { + Configuration.QueryConfiguration.SetFilter(null, true); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets selectable properties depends on of this structural type. + /// + public StructuralTypeConfiguration Select(SelectExpandType selectType, + params string[] properties) + { + Configuration.QueryConfiguration.SetSelect(properties, selectType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets selectable properties of this structural type. + /// + public StructuralTypeConfiguration Select(params string[] properties) + { + Configuration.QueryConfiguration.SetSelect(properties, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets of all properties of this structural type is selectable. + /// + public StructuralTypeConfiguration Select(SelectExpandType selectType) + { + Configuration.QueryConfiguration.SetSelect(null, selectType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets all properties of this structural type is selectable. + /// + public StructuralTypeConfiguration Select() + { + Configuration.QueryConfiguration.SetSelect(null, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the max value of $top of this structural type that a client can request + /// and the maximum number of query results of this entity type to return. + /// + public StructuralTypeConfiguration Page(int? maxTopValue, int? pageSizeValue) + { + Configuration.QueryConfiguration.SetMaxTop(maxTopValue); + Configuration.QueryConfiguration.SetPageSize(pageSizeValue); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the properties of this structural type enable paging. + /// + public StructuralTypeConfiguration Page() + { + Configuration.QueryConfiguration.SetMaxTop(null); + Configuration.QueryConfiguration.SetPageSize(null); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the maximum depth of expand result, + /// expandable properties and their of this structural type. + /// + public StructuralTypeConfiguration Expand(int maxDepth, SelectExpandType expandType, params string[] properties) + { + Configuration.QueryConfiguration.SetExpand(properties, maxDepth, expandType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the expandable properties of this structural type. + /// + public StructuralTypeConfiguration Expand(params string[] properties) + { + Configuration.QueryConfiguration.SetExpand(properties, null, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the maximum depth of expand result, + /// expandable properties of this structural type. + /// + public StructuralTypeConfiguration Expand(int maxDepth, params string[] properties) + { + Configuration.QueryConfiguration.SetExpand(properties, maxDepth, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets the expandable properties and their of this structural type. + /// + public StructuralTypeConfiguration Expand(SelectExpandType expandType, params string[] properties) + { + Configuration.QueryConfiguration.SetExpand(properties, null, expandType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets of all properties with maximum depth of expand result of this structural type. + /// + public StructuralTypeConfiguration Expand(SelectExpandType expandType, int maxDepth) + { + Configuration.QueryConfiguration.SetExpand(null, maxDepth, expandType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets all properties expandable with maximum depth of expand result of this structural type. + /// + public StructuralTypeConfiguration Expand(int maxDepth) + { + Configuration.QueryConfiguration.SetExpand(null, maxDepth, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets of all properties of this structural type. + /// + public StructuralTypeConfiguration Expand(SelectExpandType expandType) + { + Configuration.QueryConfiguration.SetExpand(null, null, expandType); + Configuration.AddedExplicitly = true; + return this; + } + + /// + /// Sets all properties expandable of this structural type. + /// + public StructuralTypeConfiguration Expand() + { + Configuration.QueryConfiguration.SetExpand(null, null, SelectExpandType.Allowed); + Configuration.AddedExplicitly = true; + return this; + } + internal NavigationPropertyConfiguration GetOrCreateNavigationProperty(Expression navigationPropertyExpression, EdmMultiplicity multiplicity) { PropertyInfo navigationProperty = PropertySelectorVisitor.GetSelectedProperty(navigationPropertyExpression); diff --git a/test/Microsoft.OData.ModelBuilder.Tests/Property/PropertyConfigurationTest.cs b/test/Microsoft.OData.ModelBuilder.Tests/Property/PropertyConfigurationTest.cs index 6ec686c..cd2844a 100644 --- a/test/Microsoft.OData.ModelBuilder.Tests/Property/PropertyConfigurationTest.cs +++ b/test/Microsoft.OData.ModelBuilder.Tests/Property/PropertyConfigurationTest.cs @@ -254,32 +254,32 @@ public void Property_IsNavigable_DoesntSetSortableAndFilterable() Assert.True(property.NotSortable); } - //[Fact] - //public void Property_QuerySettings() - //{ - // // Arrange - // StructuralTypeConfiguration structuralType = Mock.Of(); - // Mock propertyInfo = new Mock(); - // propertyInfo.SetupGet(p => p.PropertyType).Returns(typeof(int)); - // PropertyConfiguration property = new PrimitivePropertyConfiguration(propertyInfo.Object, structuralType); - - // // Act - // property.Count(); - // property.OrderBy("A", "B"); - // property.Filter(QueryOptionSetting.Disabled); - // property.Page(10, 20); - // property.Expand(5, SelectExpandType.Automatic, "a"); - - // // Assert - // Assert.Equal(SelectExpandType.Automatic, - // property.QueryConfiguration.ModelBoundQuerySettings.ExpandConfigurations["a"].ExpandType); - // Assert.Equal(5, property.QueryConfiguration.ModelBoundQuerySettings.ExpandConfigurations["a"].MaxDepth); - // Assert.Equal(10, property.QueryConfiguration.ModelBoundQuerySettings.MaxTop); - // Assert.Equal(20, property.QueryConfiguration.ModelBoundQuerySettings.PageSize); - // Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.Countable); - // Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.OrderByConfigurations["A"]); - // Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.OrderByConfigurations["B"]); - // Assert.False(property.QueryConfiguration.ModelBoundQuerySettings.DefaultEnableFilter); - //} + [Fact] + public void Property_QuerySettings() + { + // Arrange + StructuralTypeConfiguration structuralType = Mock.Of(); + Mock propertyInfo = new Mock(); + propertyInfo.SetupGet(p => p.PropertyType).Returns(typeof(int)); + PropertyConfiguration property = new PrimitivePropertyConfiguration(propertyInfo.Object, structuralType); + + // Act + property.Count(); + property.OrderBy("A", "B"); + property.Filter(false); + property.Page(10, 20); + property.Expand(5, SelectExpandType.Automatic, "a"); + + // Assert + Assert.Equal(SelectExpandType.Automatic, + property.QueryConfiguration.ModelBoundQuerySettings.ExpandConfigurations["a"].ExpandType); + Assert.Equal(5, property.QueryConfiguration.ModelBoundQuerySettings.ExpandConfigurations["a"].MaxDepth); + Assert.Equal(10, property.QueryConfiguration.ModelBoundQuerySettings.MaxTop); + Assert.Equal(20, property.QueryConfiguration.ModelBoundQuerySettings.PageSize); + Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.Countable); + Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.OrderByConfigurations["A"]); + Assert.True(property.QueryConfiguration.ModelBoundQuerySettings.OrderByConfigurations["B"]); + Assert.False(property.QueryConfiguration.ModelBoundQuerySettings.DefaultEnableFilter); + } } } diff --git a/test/Microsoft.OData.ModelBuilder.Tests/PublicApi/Microsoft.OData.ModelBuilder.PublicApi.bsl b/test/Microsoft.OData.ModelBuilder.Tests/PublicApi/Microsoft.OData.ModelBuilder.PublicApi.bsl index a2aa756..709f057 100644 --- a/test/Microsoft.OData.ModelBuilder.Tests/PublicApi/Microsoft.OData.ModelBuilder.PublicApi.bsl +++ b/test/Microsoft.OData.ModelBuilder.Tests/PublicApi/Microsoft.OData.ModelBuilder.PublicApi.bsl @@ -162,9 +162,24 @@ public abstract class Microsoft.OData.ModelBuilder.PropertyConfiguration { bool NotSortable { public get; public set; } int Order { public get; public set; } System.Reflection.PropertyInfo PropertyInfo { public get; } + Microsoft.OData.ModelBuilder.Config.QueryConfiguration QueryConfiguration { public get; public set; } System.Type RelatedClrType { public abstract get; } bool Unsortable { public get; public set; } + public Microsoft.OData.ModelBuilder.PropertyConfiguration Count () + public Microsoft.OData.ModelBuilder.PropertyConfiguration Count (bool enabled) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand () + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (int maxDepth) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType, int maxDepth) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType, string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (int maxDepth, string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Expand (int maxDepth, Microsoft.OData.ModelBuilder.SelectExpandType expandType, string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Filter () + public Microsoft.OData.ModelBuilder.PropertyConfiguration Filter (bool enabled) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Filter (string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Filter (bool enabled, string[] properties) public Microsoft.OData.ModelBuilder.PropertyConfiguration IsCountable () public Microsoft.OData.ModelBuilder.PropertyConfiguration IsExpandable () public Microsoft.OData.ModelBuilder.PropertyConfiguration IsFilterable () @@ -177,6 +192,16 @@ public abstract class Microsoft.OData.ModelBuilder.PropertyConfiguration { public Microsoft.OData.ModelBuilder.PropertyConfiguration IsNotSortable () public Microsoft.OData.ModelBuilder.PropertyConfiguration IsSortable () public Microsoft.OData.ModelBuilder.PropertyConfiguration IsUnsortable () + public Microsoft.OData.ModelBuilder.PropertyConfiguration OrderBy () + public Microsoft.OData.ModelBuilder.PropertyConfiguration OrderBy (bool enabled) + public Microsoft.OData.ModelBuilder.PropertyConfiguration OrderBy (string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration OrderBy (bool enabled, string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Page () + public Microsoft.OData.ModelBuilder.PropertyConfiguration Page (System.Nullable`1[[System.Int32]] maxTopValue, System.Nullable`1[[System.Int32]] pageSizeValue) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Select () + public Microsoft.OData.ModelBuilder.PropertyConfiguration Select (Microsoft.OData.ModelBuilder.SelectExpandType selectType) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Select (string[] properties) + public Microsoft.OData.ModelBuilder.PropertyConfiguration Select (Microsoft.OData.ModelBuilder.SelectExpandType selectType, string[] properties) } public abstract class Microsoft.OData.ModelBuilder.StructuralPropertyConfiguration : Microsoft.OData.ModelBuilder.PropertyConfiguration { @@ -208,6 +233,7 @@ public abstract class Microsoft.OData.ModelBuilder.StructuralTypeConfiguration : string Namespace { public virtual get; public virtual set; } System.Collections.Generic.IEnumerable`1[[Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration]] NavigationProperties { public virtual get; } System.Collections.Generic.IEnumerable`1[[Microsoft.OData.ModelBuilder.PropertyConfiguration]] Properties { public get; } + Microsoft.OData.ModelBuilder.Config.QueryConfiguration QueryConfiguration { public get; public set; } System.Collections.Generic.IList`1[[System.Reflection.PropertyInfo]] RemovedProperties { protected get; } internal virtual void AbstractImpl () @@ -239,8 +265,22 @@ public abstract class Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration ContainsMany (Expression`1 navigationPropertyExpression) public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration ContainsOptional (Expression`1 navigationPropertyExpression) public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration ContainsRequired (Expression`1 navigationPropertyExpression) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Count () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Count (bool enabled) public Microsoft.OData.ModelBuilder.EnumPropertyConfiguration EnumProperty (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.EnumPropertyConfiguration EnumProperty (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (int maxDepth) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType, int maxDepth) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (Microsoft.OData.ModelBuilder.SelectExpandType expandType, string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (int maxDepth, string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Expand (int maxDepth, Microsoft.OData.ModelBuilder.SelectExpandType expandType, string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Filter () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Filter (bool enabled) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Filter (string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Filter (bool enabled, string[] properties) public void HasDynamicProperties (Expression`1 propertyExpression) public void HasInstanceAnnotations (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration HasMany (Expression`1 navigationPropertyExpression) @@ -253,20 +293,30 @@ public abstract class Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration HasRequired (Expression`1 navigationPropertyExpression, Expression`1 referentialConstraintExpression, Expression`1 partnerExpression) public Microsoft.OData.ModelBuilder.NavigationPropertyConfiguration HasRequired (Expression`1 navigationPropertyExpression, Expression`1 referentialConstraintExpression, Expression`1 partnerExpression) public virtual void Ignore (Expression`1 propertyExpression) - public Microsoft.OData.ModelBuilder.LengthPropertyConfiguration Property (Expression`1 propertyExpression) - public Microsoft.OData.ModelBuilder.LengthPropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 OrderBy () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 OrderBy (bool enabled) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 OrderBy (string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 OrderBy (bool enabled, string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Page () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Page (System.Nullable`1[[System.Int32]] maxTopValue, System.Nullable`1[[System.Int32]] pageSizeValue) + public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrimitivePropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.DecimalPropertyConfiguration Property (Expression`1 propertyExpression) - public Microsoft.OData.ModelBuilder.DecimalPropertyConfiguration Property (Expression`1 propertyExpression) - public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.UntypedPropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.LengthPropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.LengthPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) - public Microsoft.OData.ModelBuilder.UntypedPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrecisionPropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.DecimalPropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrimitivePropertyConfiguration Property (Expression`1 propertyExpression) public Microsoft.OData.ModelBuilder.PrimitivePropertyConfiguration Property (Expression`1 propertyExpression) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Select () + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Select (Microsoft.OData.ModelBuilder.SelectExpandType selectType) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Select (string[] properties) + public Microsoft.OData.ModelBuilder.StructuralTypeConfiguration`1 Select (Microsoft.OData.ModelBuilder.SelectExpandType selectType, string[] properties) } public abstract class Microsoft.OData.ModelBuilder.VocabularyTermConfiguration : IRecord { @@ -985,6 +1035,11 @@ AttributeUsageAttribute(), ] public sealed class Microsoft.OData.ModelBuilder.ExpandAttribute : System.Attribute { public ExpandAttribute () + public ExpandAttribute (string[] properties) + + System.Collections.Generic.Dictionary`2[[System.String],[Microsoft.OData.ModelBuilder.Config.ExpandConfiguration]] ExpandConfigurations { public get; } + Microsoft.OData.ModelBuilder.SelectExpandType ExpandType { public get; public set; } + int MaxDepth { public get; public set; } } [ @@ -1181,6 +1236,20 @@ public class Microsoft.OData.ModelBuilder.Config.QueryableRestrictions { bool Unsortable { public get; public set; } } +public class Microsoft.OData.ModelBuilder.Config.QueryConfiguration { + public QueryConfiguration () + + Microsoft.OData.ModelBuilder.Config.ModelBoundQuerySettings ModelBoundQuerySettings { public get; public set; } + + public virtual void SetCount (bool enableCount) + public virtual void SetExpand (System.Collections.Generic.IEnumerable`1[[System.String]] properties, System.Nullable`1[[System.Int32]] maxDepth, Microsoft.OData.ModelBuilder.SelectExpandType expandType) + public virtual void SetFilter (System.Collections.Generic.IEnumerable`1[[System.String]] properties, bool enableFilter) + public virtual void SetMaxTop (System.Nullable`1[[System.Int32]] maxTop) + public virtual void SetOrderBy (System.Collections.Generic.IEnumerable`1[[System.String]] properties, bool enableOrderBy) + public virtual void SetPageSize (System.Nullable`1[[System.Int32]] pageSize) + public virtual void SetSelect (System.Collections.Generic.IEnumerable`1[[System.String]] properties, Microsoft.OData.ModelBuilder.SelectExpandType selectType) +} + public interface Microsoft.OData.ModelBuilder.Conventions.IODataModelConventionSetBuilder { Microsoft.OData.ModelBuilder.Conventions.ODataModelConventionSet Build () }