Skip to content

Support NavigationPropertyBinding paths ending in cast segments - #2504

Merged
mikepizzo merged 8 commits into
masterfrom
Fix2502
Nov 16, 2022
Merged

mikepizzo merged 8 commits into
masterfrom
Fix2502

Conversation

@mikepizzo

Copy link
Copy Markdown
Contributor

Issues

This pull request fixes #2502.

Description

OData 4.01 adds the ability to distinguish nav prop bindings to the same navigation property by type by appending a type segment.

This PR adds support to ODL to have different navigation property bindings to the same navigation property that vary by type.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

Consider only writing nav prop bindings that terminate in type segment for 4.01 responses.

@mikepizzo
mikepizzo marked this pull request as draft September 6, 2022 16:34
@mikepizzo
mikepizzo marked this pull request as ready for review September 13, 2022 21:31
return new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location);
if (lastNavProp != null && !lastNavProp.ContainsTarget)
{
// TODO: Improve error message #644.

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.

shall we improve the error message as well?

Assert.NotNull(navProp);
Assert.Equal(2, setA.NavigationPropertyBindings.Count());

// NavPropBinding for for EntityX1 should be SetX1

@xuzhg xuzhg Sep 19, 2022 •

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.

duplicate 'for' #Resolved

Assert.Equal(setX1, X1NavPropBinding.Target);
Assert.Equal(setX1, setA.FindNavigationTarget(navProp, new EdmPathExpression("Nav/NS.EntityX1")));

// NavPropBinding for for EntityX2 should be SetX2

@xuzhg xuzhg Sep 19, 2022 •

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.

duplicate 'for' #Resolved

var X1NavPropBinding = setA.NavigationPropertyBindings.FirstOrDefault(b => b.Path.PathSegments.Last() == "NS.EntityX1");
Assert.NotNull(X1NavPropBinding);
var setX1 = model.FindDeclaredNavigationSource("SetX1");
Assert.Equal(setX1, X1NavPropBinding.Target);

@xuzhg xuzhg Sep 19, 2022 •

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.

shall we use 'Assert.Same' to make sure they are referencing the same instance? #Resolved

xuzhg
xuzhg previously approved these changes Sep 19, 2022
habbes
habbes previously approved these changes Nov 11, 2022
if (navigationProperty.Name != bindingPath.PathSegments.Last())
// Last segment must be the navigation segment or a type cast segment
string lastSegment = null;
string penultimateSegment = null;

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.

Word of the day :)

@mikepizzo
mikepizzo dismissed stale reviews from habbes and xuzhg via 78052a3 November 14, 2022 20:41
# Conflicts:
#	test/FunctionalTests/Microsoft.OData.Edm.Tests/Microsoft.OData.Edm.Tests.csproj
@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 463 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +372 -91
Percentile : 82.1%

Total files changed: 12

Change summary by file extension:
.sln : +0 -0
.csproj : +51 -68
.cs : +321 -23

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@mikepizzo
mikepizzo requested review from habbes and xuzhg November 15, 2022 05:12
@mikepizzo

Copy link
Copy Markdown
Contributor Author

@habbes, @xuzhg -- addressed a couple comments and updated tests for 4.0 versus 4.01. please re-review. thanks!

True
True
Microsoft.OData.Core.tt

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.

Are they not needed again?

True
Microsoft.OData.Edm.tt

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.

removed accidently?

// Last segment must be the navigation segment or a type cast segment
string lastSegment = null;
string penultimateSegment = null;
foreach (string segment in bindingPath.PathSegments)

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.

Cannot use "LastOrDefault()"?
Then check the return is null or not?

[Theory]
public void ValidateNavigationPropertyBindingPathEndingInTypeCast(string odataVersion)
{
var entitySetWithNavProperties =

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.

maybe name it as " entitySetWithNavBindings"

"" +
"" +
"";
var entitySetWithoutNavProperties =

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.

maybe name it as " entitySetWithoutNavBindings"

@@ -81,20 +81,6 @@

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.

It seems there's no source code changed in OData.Core project.

@mikepizzo
mikepizzo merged commit 370cd96 into master Nov 16, 2022
@mikepizzo
mikepizzo deleted the Fix2502 branch November 16, 2022 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nav property bindings terminating in a type cast segment

3 participants