Skip to content

Commit f41de3f

Browse files
author
Chris Martinez
committed
Add support for composite keys for convention routes. Relates to #226
1 parent 9b8c9b7 commit f41de3f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Microsoft.AspNet.OData.Versioning.ApiExplorer/Description/ODataRouteBuilder.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,29 @@ string GetEntityKeySegment()
162162

163163
void TryAddEntityKeySegmentByConvention( StringBuilder convention )
164164
{
165-
var keys = Context.EntityKeys.ToArray();
165+
// REF: http://odata.github.io/WebApi/#13-06-KeyValueBinding
166+
var entityKeys = Context.EntityKeys.ToArray();
167+
var parameterKeys = Context.ParameterDescriptions.Where( p => p.Name.StartsWith( ODataRouteConstants.Key, OrdinalIgnoreCase ) ).ToArray();
166168

167-
if ( keys.Length != 1 || !Context.ParameterDescriptions.Any( p => ODataRouteConstants.Key.Equals( p.Name, OrdinalIgnoreCase ) ) )
169+
if ( entityKeys.Length == parameterKeys.Length )
168170
{
169171
return;
170172
}
171173

172174
convention.Append( '(' );
173-
ExpandParameterTemplate( convention, keys[0], ODataRouteConstants.Key );
175+
176+
if ( entityKeys.Length == 1 )
177+
{
178+
ExpandParameterTemplate( convention, entityKeys[0], ODataRouteConstants.Key );
179+
}
180+
else
181+
{
182+
for ( var i = 0; i < entityKeys.Length; i++ )
183+
{
184+
ExpandParameterTemplate( convention, entityKeys[i], parameterKeys[i].Name );
185+
}
186+
}
187+
174188
convention.Append( ')' );
175189
}
176190

0 commit comments

Comments
 (0)