-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathODataQuerySettings.cs
161 lines (145 loc) · 6.3 KB
/
ODataQuerySettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//-----------------------------------------------------------------------------
// <copyright file="ODataQuerySettings.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.AspNetCore.OData.Query
{
/// <summary>
/// This class describes the settings to use during query composition.
/// </summary>
public class ODataQuerySettings
{
private HandleNullPropagationOption _handleNullPropagationOption = HandleNullPropagationOption.Default;
private int? _pageSize;
private int? _modelBoundPageSize;
/// <summary>
/// Initializes a new instance of the <see cref="ODataQuerySettings" /> class.
/// </summary>
public ODataQuerySettings()
{
EnsureStableOrdering = true;
EnableConstantParameterization = true;
}
/// <summary>
/// Gets or sets the <see cref="TimeZoneInfo"/>.
/// </summary>
public TimeZoneInfo TimeZone { get; set; }
/// <summary>
/// Gets or sets the maximum number of query results to return based on the type or property.
/// </summary>
/// <value>
/// The maximum number of query results to return based on the type or property,
/// or <c>null</c> if there is no limit.
/// </value>
internal int? ModelBoundPageSize
{
get
{
return _modelBoundPageSize;
}
set
{
if (value.HasValue && value <= 0)
{
throw Error.ArgumentMustBeGreaterThanOrEqualTo("value", value, 1);
}
_modelBoundPageSize = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether query composition should
/// alter the original query when necessary to ensure a stable sort order.
/// </summary>
/// <value>A <c>true</c> value indicates the original query should
/// be modified when necessary to guarantee a stable sort order.
/// A <c>false</c> value indicates the sort order can be considered
/// stable without modifying the query. Query providers that ensure
/// a stable sort order should set this value to <c>false</c>.
/// The default value is <c>true</c>.</value>
public bool EnsureStableOrdering { get; set; }
/// <summary>
/// Gets or sets a value indicating how null propagation should
/// be handled during query composition.
/// </summary>
/// <value>
/// The default is <see cref="HandleNullPropagationOption.Default"/>.
/// </value>
public HandleNullPropagationOption HandleNullPropagation
{
get
{
return _handleNullPropagationOption;
}
set
{
HandleNullPropagationOptionHelper.Validate(value, "value");
_handleNullPropagationOption = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether constants should be parameterized. Parameterizing constants
/// would result in better performance with Entity framework.
/// </summary>
/// <value>The default value is <c>true</c>.</value>
public bool EnableConstantParameterization { get; set; }
/// <summary>
/// Gets or sets a value indicating whether queries with expanded navigations should be formulated
/// to encourage correlated sub-query results to be buffered.
/// Buffering correlated sub-query results can reduce the number of queries from N + 1 to 2
/// by buffering results from the sub-query.
/// </summary>
/// <value>The default value is <c>false</c>.</value>
public bool EnableCorrelatedSubqueryBuffering { get; set; }
/// <summary>
/// Gets or sets a value indicating which query options should be ignored when applying queries.
/// </summary>
public AllowedQueryOptions IgnoredQueryOptions { get; set; } = AllowedQueryOptions.None;
/// <summary>
/// Gets or sets a value indicating which nested query options should be ignored typically within select and expand.
/// </summary>
public AllowedQueryOptions IgnoredNestedQueryOptions { get; set; } = AllowedQueryOptions.None;
/// <summary>
/// Gets or sets the maximum number of query results to return.
/// </summary>
/// <value>
/// The maximum number of query results to return, or <c>null</c> if there is no limit.
/// </value>
public int? PageSize
{
get
{
return _pageSize;
}
set
{
if (value.HasValue && value <= 0)
{
throw Error.ArgumentMustBeGreaterThanOrEqualTo("value", value, 1);
}
_pageSize = value;
}
}
/// <summary>
/// Honor $filter inside $expand of non-collection navigation property.
/// The expanded property is only populated when the filter evaluates to true.
/// This setting is false by default.
/// </summary>
public bool HandleReferenceNavigationPropertyExpandFilter { get; set; }
internal void CopyFrom(ODataQuerySettings settings)
{
TimeZone = settings.TimeZone;
EnsureStableOrdering = settings.EnsureStableOrdering;
EnableConstantParameterization = settings.EnableConstantParameterization;
HandleNullPropagation = settings.HandleNullPropagation;
PageSize = settings.PageSize;
ModelBoundPageSize = settings.ModelBoundPageSize;
HandleReferenceNavigationPropertyExpandFilter = settings.HandleReferenceNavigationPropertyExpandFilter;
EnableCorrelatedSubqueryBuffering = settings.EnableCorrelatedSubqueryBuffering;
IgnoredQueryOptions = settings.IgnoredQueryOptions;
IgnoredNestedQueryOptions = settings.IgnoredNestedQueryOptions;
}
}
}