-
Notifications
You must be signed in to change notification settings - Fork 351
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
method to get all navigation property bindings #2157
Conversation
You'll need to update the publicapi baseline for the new method. |
Is the common pattern to get all nav prop bindings for the entire container, or to get the nav prop bindings for a particular entityset/singleton? |
In my experience, yes. For example, when Graph needs to decide if and how deep insert is possible, they are building a sort of map where to "find" an entity of a given type. This came up in a bug a few month back and I believe it would be good to encapsulate and support a way to do this without understanding the full interface hierarchy of EDM. More info in the associated issue#2060 |
/// </summary> | ||
/// <param name="container">Reference to the calling object.</param> | ||
/// <returns>collection of pairs of container element and NavigationPropertyBindings.</returns> | ||
public static IEnumerable<(IEdmEntityContainerElement, IEdmNavigationPropertyBinding)> GetNavigationPropertyBindings(this IEdmEntityContainer container) |
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.
Will the caller be interested in the specific kind of IEdmEntityContainerElement
returned for each element? We are already casting inside this method, it would be a shame for the caller to have to do so as well if we can avoid it
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.
it is true that a user would need to cast the first element of the pair if they are interested in more than what IEdmEntityContainerElement provides (which is the name, container, kind and a few extension methods).
But I doubt that this is common since this API is specifically about all bindings, independent of the type of "bindable" container element.
} | ||
break; | ||
case IEdmSingleton singleton: | ||
foreach (var binding in singleton.NavigationPropertyBindings) |
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.
It's a more fundamental change, but I wonder if it would make sense for IEdmEntitySet
and IEdmSingleton
to derive from a common interface that has NavigationPropertyBindings
on it. Then this whole method is sort of obsolete (or at least very derivative):
return container
.AllElements()
.OfType<IEdmWithNavPropertyBindings>()
.SelectMany(element => element.NavigationPropertyBindings.Select(binding => (element, binding)));
54d3aeb
to
ca43c4e
Compare
...unctionalTests/Microsoft.OData.Edm.Tests/Csdl/Semantics/CsdlSemanticsEntityContainerTests.cs
Outdated
Show resolved
Hide resolved
var bindings = container.GetNavigationPropertyBindings().ToList(); | ||
|
||
// assert | ||
Assert.Equal(2, bindings.Count); |
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.
I think we should also assert the actual bindings are what's expected?
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.
@habbes Added requested asserts
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Add an officially supported method to get all navigation property bindings.
Retrieving all navigation property bindings requires quite some knowledge of the edm model implementation and casting.
This method encapsulated this logic.
Issues
addresses #2060