Skip to content

Commit 408b122

Browse files
author
Caitlin Bales (MSFT)
committed
Add singleton's EntitySet URL to the odata.id URL
This is for the C# generated templates. Currently in the templates, we generate @odata.id based off an EntitySet name, which is an absolute URL. In the case of a singleton, we want to navigate to that singleton's relevant EntitySet
1 parent a6c6b25 commit 408b122

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public string GetPostAsyncMethodForReferencesRequest(OdcmProperty odcmProperty)
137137
var serviceNavigationProperty = odcmProperty.GetServiceCollectionNavigationPropertyForPropertyType();
138138
if (serviceNavigationProperty == null)
139139
return string.Empty;
140+
141+
//Append the singleton's navigation type to the @odata.id if relevant
142+
var implicitNavigationProperty = string.Empty;
143+
if (serviceNavigationProperty.GetType() == typeof(OdcmSingleton))
144+
implicitNavigationProperty = "/" + odcmProperty.Name;
140145

141146
var stringBuilder = new StringBuilder();
142147

@@ -178,7 +183,7 @@ public string GetPostAsyncMethodForReferencesRequest(OdcmProperty odcmProperty)
178183
stringBuilder.Append(" }");
179184
stringBuilder.Append(Environment.NewLine);
180185
stringBuilder.Append(Environment.NewLine);
181-
stringBuilder.AppendFormat(" var requestBody = new ReferenceRequestBody {{ ODataId = string.Format(\"{{0}}/{0}/{{1}}\", this.Client.BaseUrl, {1}.Id) }};", serviceNavigationProperty.Name, sanitizedPropertyName);
186+
stringBuilder.AppendFormat(" var requestBody = new ReferenceRequestBody {{ ODataId = string.Format(\"{{0}}/{0}{1}/{{1}}\", this.Client.BaseUrl, {2}.Id) }};", serviceNavigationProperty.Name, implicitNavigationProperty, sanitizedPropertyName);
182187
stringBuilder.Append(Environment.NewLine);
183188
stringBuilder.AppendFormat(" return this.SendAsync(requestBody, cancellationToken);");
184189
stringBuilder.Append(Environment.NewLine);

0 commit comments

Comments
 (0)