Skip to content

Support FromBody parameters with actions and functions - #579

Merged
xuzhg merged 1 commit into
OData:mainfrom
gathogojr:fix/571-support-frombody-parameters-with-actions-and-functions
Apr 27, 2022
Merged

Support FromBody parameters with actions and functions#579
xuzhg merged 1 commit into
OData:mainfrom
gathogojr:fix/571-support-frombody-parameters-with-actions-and-functions

Conversation

@gathogojr

@gathogojr gathogojr commented Apr 27, 2022

Copy link
Copy Markdown
Contributor

Fixes #571

The target navigation source is unresolved at the time of initializing an ActionSegmentTemplate and a FunctionSegmentTemplate. For that reason, the NavigationSource property of the ODataSegmentTemplate is initialized to null. Subsequently when we create an OperationSegment from the TryTranslate method of either of the two templates, the EdmType and EntitySet properties of the segment are initialized to null. This is the reason for the error exhibited in the reported issue.

We fix the issue in this PR by using the entity set annotation to get the target navigation source. This annotation is set when ReturnsFromEntitySet method (and similar variants) are called when using the model builder to initialize the Edm model.
By fixing this we dealt with a technical debt in the form of a comment left in ODataOutputFormatterHelper

@gathogojr
gathogojr force-pushed the fix/571-support-frombody-parameters-with-actions-and-functions branch from fde37b8 to 99e496b Compare April 27, 2022 09:37
@ElizabethOkerio

Copy link
Copy Markdown
Contributor

@gathogojr please add description of the changes you've made.


ODataPath path = request.ODataFeature().Path;
IEdmNavigationSource targetNavigationSource = GetTargetNavigationSource(path, model);
IEdmNavigationSource targetNavigationSource = path.GetNavigationSource();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand why you did away with the GetTargetNavigationSource method. and called the path.GetNavigationSource directly. Does it mean the path.LastSegment is always null at this point?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetTargetNavigationSource method defined in this class was a workaround to the problem that we're fixing from the TryTranslate methods of ActionSegmentTemplate and FunctionSegmentTemplate. It's not necessary to return it after the fix that we applied

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah I see

Comment thread src/Microsoft.AspNetCore.OData/Routing/Template/ActionSegmentTemplate.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Routing/Template/ActionSegmentTemplate.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Routing/Template/FunctionSegmentTemplate.cs Outdated
@gathogojr
gathogojr force-pushed the fix/571-support-frombody-parameters-with-actions-and-functions branch from 99e496b to 7813059 Compare April 27, 2022 11:42
@gathogojr
gathogojr force-pushed the fix/571-support-frombody-parameters-with-actions-and-functions branch from 7813059 to c3564f2 Compare April 27, 2022 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use either [FromBody] Foo entity or [FromBody] Delta<Foo> entity with [HttpPost] method

3 participants