Skip to content

Commit 6e4e5f6

Browse files
Merge pull request #147 from microsoftgraph/supportNavPathBindings
Support nav path bindings
2 parents e2d65f7 + d4a95ca commit 6e4e5f6

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

GraphODataTemplateWriter.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Global
3434
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3535
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3636
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
37-
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
38-
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.ActiveCfg = Debug|Any CPU
38+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.Build.0 = Debug|Any CPU
3939
EndGlobalSection
4040
GlobalSection(SolutionProperties) = preSolution
4141
HideSolutionNode = FALSE

Templates/CSharp/Base/CollectionRequest.Base.template.tt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ public string GetPostAsyncMethodForReferencesRequest(OdcmProperty odcmProperty)
143143
if (serviceNavigationProperty == null)
144144
return string.Empty;
145145

146-
//Append the singleton's navigation type to the @odata.id if relevant
147146
var implicitNavigationProperty = string.Empty;
147+
148+
// If the odcmProperty is a part of Singleton, then we need to determine whether there is a
149+
// NavigationPropertyBinding generation hint. If there is, then we need to use it for
150+
// creating the URL of a reference entity in a POST body.
148151
if (serviceNavigationProperty.GetType() == typeof(OdcmSingleton))
149-
implicitNavigationProperty = "/" + odcmProperty.Name;
152+
implicitNavigationProperty = "/" + odcmProperty.GetImplicitPropertyName((OdcmSingleton)serviceNavigationProperty);
150153

151154
var stringBuilder = new StringBuilder();
152155

src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ public static OdcmProperty GetServiceCollectionNavigationPropertyForPropertyType
208208
}
209209
}
210210

211+
public static string GetImplicitPropertyName(this OdcmProperty property, OdcmSingleton singleton)
212+
{
213+
var implicitPropertyName = property.Name;
214+
// Default behavior
215+
if (singleton.NavigationPropertyBindings.Count() > 0)
216+
{
217+
var target = singleton.NavigationPropertyBindings.Where(kv => kv.Key.EndsWith(property.Name)).Select(kvp => kvp.Value).FirstOrDefault();
218+
if (target != null)
219+
{
220+
implicitPropertyName = target;
221+
}
222+
}
223+
return implicitPropertyName;
224+
}
225+
211226
public static IEnumerable<OdcmProperty> NavigationProperties(this OdcmClass odcmClass)
212227
{
213228
return odcmClass.Properties.Where(prop => prop.IsNavigation());

submodules/vipr

Submodule vipr updated 655 files

0 commit comments

Comments
 (0)