|
3 | 3 | <#@ include file="Request.Base.template.tt"#> |
4 | 4 | <#+ |
5 | 5 |
|
| 6 | +using System.Linq.Enumerable; |
| 7 | + |
6 | 8 | // ------------------------------------------------------------- |
7 | 9 | // Methods for standard entity collection classes |
8 | 10 | // ------------------------------------------------------------- |
@@ -146,7 +148,58 @@ public string GetPostAsyncMethodForReferencesRequest(OdcmProperty odcmProperty) |
146 | 148 | //Append the singleton's navigation type to the @odata.id if relevant |
147 | 149 | var implicitNavigationProperty = string.Empty; |
148 | 150 | 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 | + |
150 | 203 |
|
151 | 204 | var stringBuilder = new StringBuilder(); |
152 | 205 |
|
|
0 commit comments