Skip to content

Commit c0fa08d

Browse files
committed
Update VIPR ref, add initial incomplete support of NavigationBindingPath as generation hints
1 parent b08c615 commit c0fa08d

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
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: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<#@ include file="Request.Base.template.tt"#>
44
<#+
55

6+
using System.Linq.Enumerable;
7+
68
// -------------------------------------------------------------
79
// Methods for standard entity collection classes
810
// -------------------------------------------------------------
@@ -146,7 +148,58 @@ public string GetPostAsyncMethodForReferencesRequest(OdcmProperty odcmProperty)
146148
//Append the singleton's navigation type to the @odata.id if relevant
147149
var implicitNavigationProperty = string.Empty;
148150
if (serviceNavigationProperty.GetType() == typeof(OdcmSingleton))
149-
implicitNavigationProperty = "/" + odcmProperty.Name;
151+
{
152+
var singleton = (OdcmSingleton)serviceNavigationProperty;
153+
154+
// (1) Get all of the keys (Binding Paths) that contain our target path name, in this case, "teachers". This should be the end part of the BindingPath.
155+
IEnumerable<string> keys = singleton.NavigationPropertyBindings.Where(kvp => kvp.Key.EndsWith(odcmProperty.Name)).Select(kvp => kvp.Key);
156+
// TODO: if keys.Count == 0, we need to short circuit this.
157+
158+
/*
159+
// Check that we actually matched a key. If we have NavigationPropertyBindings and we didn't find a potential match, then we have an error
160+
if (singleton.NavigationPropertyBindings.Count != 0 && keys.Count() == 0) // I don't think this is good.
161+
{
162+
throw new Exception("Expected that a prospect key match is found. No key was found.");
163+
}
164+
*/
165+
166+
// (2) We need to query the paths in {keys} against the entity (odcmProperty.Class) that contains this navigation property (odcmProperty).
167+
// We need to determine the unique binding path from the singleton through the entity on to this navigation property, query the keys
168+
// for it, and then get the target. There could be 1 or more hops that we need to account for.
169+
170+
// odcmProperty.Name; // --> "teachers"
171+
172+
var navPropClassToFind = odcmProperty.Class.Name; // -- > "educationClass";
173+
string firstBindingPathSegment = ""; // We are incorrectly assuming to segment.
174+
175+
176+
foreach (OdcmProperty prop in (singleton.Type as OdcmEntityClass).Properties)
177+
{
178+
if (prop.Type.Name == navPropClassToFind)
179+
{
180+
firstBindingPathSegment = prop.Name;
181+
break;
182+
}
183+
}
184+
185+
string secondBindingPathSegment = odcmProperty.Name;
186+
187+
//string bindingPath = firstBindingPathSegment + "/" + keys.First(); // TODO: Need to fix this.
188+
string bindingPath = firstBindingPathSegment + "/" + secondBindingPathSegment;
189+
190+
string bindingTarget;
191+
192+
if (singleton.NavigationPropertyBindings.TryGetValue(bindingPath, out bindingTarget))
193+
{
194+
// We found the target
195+
implicitNavigationProperty = "/" + bindingTarget;
196+
}
197+
else
198+
implicitNavigationProperty = "/" + odcmProperty.Name;
199+
200+
201+
}
202+
150203

151204
var stringBuilder = new StringBuilder();
152205

submodules/vipr

Submodule vipr updated 655 files

0 commit comments

Comments
 (0)