-
Notifications
You must be signed in to change notification settings - Fork 182
Add Constructor to ODataQueryOptions and ODataQueryOptions<TEntity> for Dictionary-Based Initialization Without HttpRequest and optional IEdmModel #1537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WanjohiSammy
wants to merge
7
commits into
main
Choose a base branch
from
feature/odataqueryoptions-new-constructor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
17bf41c
Add ODataQueryOptions constrctor
WanjohiSammy 6fc9974
support null IEdmModel
WanjohiSammy 3b7d79a
nit
WanjohiSammy ee88f28
Add public ODataQueryOptions constructors
WanjohiSammy 8f7455c
Handle null Request
WanjohiSammy 0e15185
Fix test baseline for PublicAPI
WanjohiSammy dcc93a4
Merge remote-tracking branch 'origin' into feature/odataqueryoptions-…
WanjohiSammy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,66 @@ public ODataQueryOptions(ODataQueryContext context, HttpRequest request) | |
| Initialize(context); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the given query parameters and context. | ||
| /// </summary> | ||
| /// <param name="queryParameters">The OData query parameters as a dictionary.</param> | ||
| /// <param name="model">The EdmModel that includes the <see cref="IEdmType"/> corresponding to | ||
| /// the given <paramref name="elementClrType"/>.</param> | ||
| /// <param name="elementClrType">The CLR type of the element of the collection being queried.</param> | ||
| /// <param name="path">The parsed <see cref="ODataPath"/>.</param> | ||
| public ODataQueryOptions(IDictionary<string, string> queryParameters, Type elementClrType, IEdmModel model = null, ODataPath path = null) | ||
| { | ||
| if (queryParameters == null) | ||
| { | ||
| throw Error.ArgumentNull(nameof(queryParameters)); | ||
| } | ||
|
|
||
| if (elementClrType == null) | ||
| { | ||
| throw Error.ArgumentNull(nameof(elementClrType)); | ||
| } | ||
|
|
||
| if (model == null) | ||
| { | ||
| RawValues = new ODataRawQueryOptions(); | ||
|
|
||
| BuildQueryOptionsOnly(queryParameters); | ||
| return; | ||
| } | ||
|
|
||
| ODataQueryContext context = new ODataQueryContext(model ?? EdmCoreModel.Instance, elementClrType, path); | ||
|
|
||
| Context = context; | ||
| Request = context.Request; | ||
|
|
||
| RawValues = new ODataRawQueryOptions(); | ||
|
|
||
| // Use the provided dictionary directly | ||
| _queryOptionParser = new ODataQueryOptionParser( | ||
| context.Model, | ||
| context.ElementType, | ||
| context.NavigationSource, | ||
| queryParameters, | ||
| context.RequestContainer); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where do you get the RequestContainer? you use 'context.RequestContainer', is it valid? |
||
|
|
||
| var uriResolver = context.RequestContainer?.GetService<ODataUriResolver>(); | ||
| if (uriResolver != null) | ||
| { | ||
| _queryOptionParser.Resolver = uriResolver; | ||
| _enableNoDollarSignQueryOptions = uriResolver.EnableNoDollarQueryOptions; | ||
| } | ||
| else | ||
| { | ||
| _queryOptionParser.Resolver = ODataQueryContext.DefaultCaseInsensitiveResolver; | ||
| _enableNoDollarSignQueryOptions = false; | ||
| } | ||
|
|
||
| BuildQueryOptions(queryParameters); | ||
|
|
||
| Validator = context.GetODataQueryValidator(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the request message associated with this instance. | ||
| /// </summary> | ||
|
|
@@ -1052,7 +1112,8 @@ private void BuildQueryOptions(IDictionary<string, string> queryParameters) | |
| Context, _queryOptionParser); | ||
| } | ||
|
|
||
| if (Request.IsCountRequest()) | ||
| // Ensure Request is not null before checking for CountRequest | ||
| if (Request != null && Request.IsCountRequest()) | ||
| { | ||
| Count = new CountQueryOption( | ||
| "true", | ||
|
|
@@ -1066,6 +1127,80 @@ private void BuildQueryOptions(IDictionary<string, string> queryParameters) | |
| } | ||
| } | ||
|
|
||
| private void BuildQueryOptionsOnly(IDictionary<string, string> queryParameters) | ||
| { | ||
| foreach (KeyValuePair<string, string> kvp in queryParameters) | ||
| { | ||
| switch (kvp.Key.ToLowerInvariant()) | ||
| { | ||
| case "$filter": | ||
| ThrowIfEmpty(kvp.Value, "$filter"); | ||
| RawValues.Filter = kvp.Value; | ||
| Filter = new FilterQueryOption(kvp.Value); | ||
| break; | ||
| case "$orderby": | ||
| ThrowIfEmpty(kvp.Value, "$orderby"); | ||
| RawValues.OrderBy = kvp.Value; | ||
| OrderBy = new OrderByQueryOption(kvp.Value); | ||
| break; | ||
| case "$top": | ||
| ThrowIfEmpty(kvp.Value, "$top"); | ||
| RawValues.Top = kvp.Value; | ||
| Top = new TopQueryOption(kvp.Value); | ||
| break; | ||
| case "$skip": | ||
| ThrowIfEmpty(kvp.Value, "$skip"); | ||
| RawValues.Skip = kvp.Value; | ||
| Skip = new SkipQueryOption(kvp.Value); | ||
| break; | ||
| case "$select": | ||
| RawValues.Select = kvp.Value; | ||
| break; | ||
| case "$count": | ||
| ThrowIfEmpty(kvp.Value, "$count"); | ||
| RawValues.Count = kvp.Value; | ||
| Count = new CountQueryOption(kvp.Value); | ||
| break; | ||
| case "$expand": | ||
| RawValues.Expand = kvp.Value; | ||
| break; | ||
| case "$format": | ||
| RawValues.Format = kvp.Value; | ||
| break; | ||
| case "$skiptoken": | ||
| RawValues.SkipToken = kvp.Value; | ||
| SkipToken = new SkipTokenQueryOption(kvp.Value); | ||
| break; | ||
| case "$deltatoken": | ||
| RawValues.DeltaToken = kvp.Value; | ||
| break; | ||
| case "$apply": | ||
| ThrowIfEmpty(kvp.Value, "$apply"); | ||
| RawValues.Apply = kvp.Value; | ||
| Apply = new ApplyQueryOption(kvp.Value); | ||
| break; | ||
| case "$compute": | ||
| ThrowIfEmpty(kvp.Value, "$compute"); | ||
| RawValues.Compute = kvp.Value; | ||
| Compute = new ComputeQueryOption(kvp.Value); | ||
| break; | ||
| case "$search": | ||
| ThrowIfEmpty(kvp.Value, "$search"); | ||
| RawValues.Search = kvp.Value; | ||
| Search = new SearchQueryOption(kvp.Value); | ||
| break; | ||
| default: | ||
| // we don't throw if we can't recognize the query | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(RawValues.Select) || !string.IsNullOrWhiteSpace(RawValues.Expand)) | ||
| { | ||
| SelectExpand = new SelectExpandQueryOption(RawValues.Select, RawValues.Expand); | ||
| } | ||
| } | ||
|
|
||
| private static bool IsAvailableODataQueryOption(object queryOption, ODataQuerySettings querySettings, AllowedQueryOptions queryOptionFlag) | ||
| { | ||
| return (queryOption != null) && | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion is to accept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which services are required by
ODataQueryOptions?