Skip to content

Commit 1f09f3a

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Generate navigation property templates by convention. Resolves #463
1 parent 9ab464d commit 1f09f3a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Common.OData.ApiExplorer/AspNet.OData/Routing/ODataRouteBuilder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void AppendEntitySetOrOperation( IList<string> segments )
135135
case EntitySet:
136136
builder.Append( controllerName );
137137
AppendEntityKeysFromConvention( builder );
138+
AppendNavigationPropertyFromConvention( builder );
138139
break;
139140
case BoundOperation:
140141
builder.Append( controllerName );
@@ -202,6 +203,23 @@ void AppendEntityKeysFromConvention( StringBuilder builder )
202203
}
203204
}
204205

206+
void AppendNavigationPropertyFromConvention( StringBuilder builder )
207+
{
208+
Contract.Requires( builder != null );
209+
210+
var actionName = Context.ActionDescriptor.ActionName;
211+
var properties = Context.EntitySet.EntityType().NavigationProperties();
212+
var property = properties.FirstOrDefault( p => actionName.EndsWith( p.Name, OrdinalIgnoreCase ) );
213+
214+
if ( property == null )
215+
{
216+
return;
217+
}
218+
219+
builder.Append( '/' );
220+
builder.Append( property.Name );
221+
}
222+
205223
void AppendParametersFromConvention( StringBuilder builder, IEdmOperation operation )
206224
{
207225
Contract.Requires( builder != null );

0 commit comments

Comments
 (0)