diff --git a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs index 848b7f3686..9d4e206a69 100644 --- a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs +++ b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs @@ -1646,6 +1646,40 @@ public static IEnumerable OperationImports(this IEdmEntityC return container.AllElements().OfType(); } + /// + /// Returns navigation property bindings with their corresponding container elements (entity set or singleton) + /// + /// Reference to the calling object. + /// Collection of pairs of container element and navigation property bindings. + public static IEnumerable> GetNavigationPropertyBindings(this IEdmEntityContainer container) + { + EdmUtil.CheckArgumentNull(container, "container"); + + IEnumerable elements = container.AllElements(); + + foreach(IEdmEntityContainerElement element in elements) + { + switch (element) + { + case IEdmEntitySet entitySet: + foreach(IEdmNavigationPropertyBinding binding in entitySet.NavigationPropertyBindings) + { + yield return Tuple.Create(entitySet, binding); + } + break; + case IEdmSingleton singleton: + foreach (IEdmNavigationPropertyBinding binding in singleton.NavigationPropertyBindings) + { + yield return Tuple.Create< IEdmEntityContainerElement, IEdmNavigationPropertyBinding>(singleton, binding); + } + break; + default: + break; + } + } + } + + #endregion #region IEdmTypeReference diff --git a/test/FunctionalTests/Microsoft.OData.Edm.Tests/Csdl/Semantics/CsdlSemanticsEntityContainerTests.cs b/test/FunctionalTests/Microsoft.OData.Edm.Tests/Csdl/Semantics/CsdlSemanticsEntityContainerTests.cs index 1fe2bb5525..3a7bb3b3d8 100644 --- a/test/FunctionalTests/Microsoft.OData.Edm.Tests/Csdl/Semantics/CsdlSemanticsEntityContainerTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Edm.Tests/Csdl/Semantics/CsdlSemanticsEntityContainerTests.cs @@ -70,5 +70,45 @@ 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 = new CsdlSemanticsEntityContainer( + new CsdlSemanticsSchema( + new CsdlSemanticsModel( + csdlModel, + new EdmDirectValueAnnotationsManager(), + Enumerable.Empty()), + schema), + csdlEntityContainer); + var bindings = container.GetNavigationPropertyBindings().ToList(); + + // assert + Assert.Equal(2, bindings.Count); + var entitySet = Assert.IsType(bindings[0].Item1); + var singleton = Assert.IsType(bindings[1].Item1); + Assert.Equal("EntitySet1", entitySet.Name); + Assert.Equal("Singleton", singleton.Name); + var navigationPropertyBinding1 = Assert.IsType(bindings[0].Item2); + var navigationPropertyBinding2 = Assert.IsType(bindings[1].Item2); + Assert.Equal("foo", navigationPropertyBinding1.Path.Path); + Assert.Equal("bar", navigationPropertyBinding1.Target.Name); + Assert.Equal("foo", navigationPropertyBinding2.Path.Path); + Assert.Equal("bar", navigationPropertyBinding2.Target.Name); + } } } diff --git a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.net45.bsl b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.net45.bsl index 7c914234f0..cc0d867558 100644 --- a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.net45.bsl +++ b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.net45.bsl @@ -2025,6 +2025,11 @@ public sealed class Microsoft.OData.Edm.ExtensionMethods { ] public static string GetLongDescriptionAnnotation (Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable target) + [ + ExtensionAttribute(), + ] + public static System.Collections.Generic.IEnumerable`1[[System.Tuple`2[[Microsoft.OData.Edm.IEdmEntityContainerElement],[Microsoft.OData.Edm.IEdmNavigationPropertyBinding]]]] GetNavigationPropertyBindings (Microsoft.OData.Edm.IEdmEntityContainer container) + [ ExtensionAttribute(), ] diff --git a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard1.1.bsl b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard1.1.bsl index df3c0a5326..94c3b1a8dc 100644 --- a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard1.1.bsl +++ b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard1.1.bsl @@ -2025,6 +2025,11 @@ public sealed class Microsoft.OData.Edm.ExtensionMethods { ] public static string GetLongDescriptionAnnotation (Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable target) + [ + ExtensionAttribute(), + ] + public static System.Collections.Generic.IEnumerable`1[[System.Tuple`2[[Microsoft.OData.Edm.IEdmEntityContainerElement],[Microsoft.OData.Edm.IEdmNavigationPropertyBinding]]]] GetNavigationPropertyBindings (Microsoft.OData.Edm.IEdmEntityContainer container) + [ ExtensionAttribute(), ] diff --git a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard2.0.bsl b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard2.0.bsl index 7c914234f0..cc0d867558 100644 --- a/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard2.0.bsl +++ b/test/PublicApiTests/BaseLine/Microsoft.OData.PublicApi.netstandard2.0.bsl @@ -2025,6 +2025,11 @@ public sealed class Microsoft.OData.Edm.ExtensionMethods { ] public static string GetLongDescriptionAnnotation (Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable target) + [ + ExtensionAttribute(), + ] + public static System.Collections.Generic.IEnumerable`1[[System.Tuple`2[[Microsoft.OData.Edm.IEdmEntityContainerElement],[Microsoft.OData.Edm.IEdmNavigationPropertyBinding]]]] GetNavigationPropertyBindings (Microsoft.OData.Edm.IEdmEntityContainer container) + [ ExtensionAttribute(), ]