Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ODataPathExtensions.GetNavigationSource #1161

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions src/Microsoft.AspNetCore.OData/Routing/ODataPathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,58 @@ public static IEdmNavigationSource GetNavigationSource(this ODataPath path)
throw Error.ArgumentNull(nameof(path));
}

ODataPathNavigationSourceHandler handler = new ODataPathNavigationSourceHandler();
path.WalkWith(handler);
return handler.NavigationSource;
for (int i = path.Count - 1; i >= 0; --i)
{
ODataPathSegment segment = path[i];
if (segment is EntitySetSegment entitySetSegment)
{
return entitySetSegment.EntitySet;
}

if (segment is KeySegment keySegment)
{
return keySegment.NavigationSource;
}

if (segment is NavigationPropertyLinkSegment navigationPropertyLinkSegment)
{
return navigationPropertyLinkSegment.NavigationSource;
}

if (segment is NavigationPropertySegment navigationPropertySegment)
{
return navigationPropertySegment.NavigationSource;
}

if (segment is OperationImportSegment operationImportSegment)
{
return operationImportSegment.EntitySet;
}

if (segment is OperationSegment operationSegment)
{
return operationSegment.EntitySet;
}

if (segment is SingletonSegment singleton)
{
return singleton.Singleton;
}

if (segment is TypeSegment typeSegment)
{
return typeSegment.NavigationSource;
}

if (segment is PropertySegment)
{
continue;
}

return null;
}

return null;
}

/// <summary>
Expand Down