-
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
Changes from 1 commit
5b18c01
ca43c4e
1940668
8af9ba2
d937cd2
2e3d3f7
e3d36cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1646,6 +1646,39 @@ public static IEnumerable<IEdmOperationImport> OperationImports(this IEdmEntityC | |
return container.AllElements().OfType<IEdmOperationImport>(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns NavigationPropertyBindings with their corresponding container elements (EntitySet or Singelton) | ||
/// </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) | ||
gathogojr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
EdmUtil.CheckArgumentNull(container, "container"); | ||
|
||
var elements = container.AllElements(); | ||
chrisspre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
foreach(var element in elements) | ||
{ | ||
switch (element) | ||
{ | ||
case IEdmEntitySet entitySet: | ||
foreach(var binding in entitySet.NavigationPropertyBindings) | ||
{ | ||
yield return (entitySet, binding); | ||
gathogojr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
break; | ||
case IEdmSingleton singleton: | ||
foreach (var binding in singleton.NavigationPropertyBindings) | ||
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. It's a more fundamental change, but I wonder if it would make sense for
|
||
{ | ||
yield return (singleton, binding); | ||
gathogojr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
#endregion | ||
|
||
#region IEdmTypeReference | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,5 +70,28 @@ public void EnsureActionImportActionPropertyIsUnresolvedAction() | |
Assert.Equal(EdmContainerElementKind.ActionImport, imports[0].ContainerElementKind); | ||
Assert.Null(imports[0].EntitySet); | ||
} | ||
|
||
[Fact] | ||
public void NavigationPropertyBindingsReturned() | ||
{ | ||
// arrange | ||
var entitySet1 = new CsdlEntitySet("EntitySet1", "unknown", new[] { | ||
new CsdlNavigationPropertyBinding("foo", "bar", testLocation) | ||
}, testLocation); | ||
var singleton1 = new CsdlSingleton("Singleton", "unknown", new[] { | ||
new CsdlNavigationPropertyBinding("foo", "bar", testLocation) | ||
}, testLocation); | ||
var csdlEntityContainer = CsdlBuilder.EntityContainer("Container", entitySets: new [] { entitySet1 }, singletons: new[] { singleton1 } ); | ||
var schema = CsdlBuilder.Schema("FQ.NS", csdlEntityContainers: new CsdlEntityContainer[] { csdlEntityContainer }); | ||
var csdlModel = new CsdlModel(); | ||
csdlModel.AddSchema(schema); | ||
|
||
// act | ||
var container = (IEdmEntityContainer)csdlEntityContainer; | ||
gathogojr marked this conversation as resolved.
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @habbes Added requested asserts |
||
} | ||
} | ||
} |
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 itThere 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.