You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently working on a project where we want to have an OData service in front of an other OData service. The main reason for this is that the second OData service is internal and allows more operations than the first one.
So in our controller we are basically using an OData client and let the [EnableQuery] do it's work:
public class CustomerController : ODataController
{
[HttpGet]
[EnableQuery(PageSize = 25)]
public IQueryable<Customer> Get()
{
var client = new Client(new Uri("https://localhost:5001/odata"));
return client.Customers;
}
}
For a lot of simple functionality this is working without issue. Since Customers implement IQueryable this libary can pass on most of the query parameters like $top, $skip, $orderby, etc.
However, when using $expand or $select, I get exceptions, which I don't get when I replace the OData client with DBContext from EF Core:
ystem.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: Stack empty.
at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
at System.Collections.Generic.Stack`1.Peek()
at Microsoft.OData.Client.SelectExpandPathBuilder.get_ParamExpressionInScope()
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.VisitConditional(ConditionalExpression c)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.Analyze(Expression e, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.Analyze(MemberInitExpression mie, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.VisitMemberInit(MemberInitExpression init)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.Analyze(Expression e, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.Analyze(MemberInitExpression mie, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.VisitMemberInit(MemberInitExpression init)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ProjectionAnalyzer.NonEntityProjectionAnalyzer.Analyze(Expression e, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.Analyze(LambdaExpression e, SelectExpandPathBuilder pb, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.AnalyzeResourceExpression(LambdaExpression lambda, ResourceExpression resource, DataServiceContext context)
at Microsoft.OData.Client.ProjectionAnalyzer.Analyze(LambdaExpression le, ResourceExpression re, Boolean matchMembers, DataServiceContext context)
at Microsoft.OData.Client.ResourceBinder.AnalyzeProjection(MethodCallExpression mce, SequenceMethod sequenceMethod, Expression& e)
at Microsoft.OData.Client.ResourceBinder.VisitMethodCall(MethodCallExpression mce)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ALinqExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
at Microsoft.OData.Client.ALinqExpressionVisitor.VisitMethodCall(MethodCallExpression m)
at Microsoft.OData.Client.ResourceBinder.VisitMethodCall(MethodCallExpression mce)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ResourceBinder.Bind(Expression e, DataServiceContext context)
at Microsoft.OData.Client.DataServiceQueryProvider.Translate(Expression e)
at Microsoft.OData.Client.DataServiceQuery`1.Translate()
at Microsoft.OData.Client.DataServiceQuery`1.Execute()
at Microsoft.OData.Client.DataServiceQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Microsoft.AspNetCore.OData.Query.Container.TruncatedCollection`1..ctor(IQueryable`1 source, Int32 pageSize, Boolean parameterize)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.LimitResults[T](IQueryable`1 queryable, Int32 limit, Boolean parameterize, Boolean& resultsLimited)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.LimitResults(IQueryable queryable, Int32 limit, Boolean parameterize, Boolean& resultsLimited)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyPaging(IQueryable result, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext)
at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.OData.Routing.ODataRouteDebugMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Is there something I might be doing wrong here, or is only EF Core supported by the AspNetCoreOData project?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am currently working on a project where we want to have an OData service in front of an other OData service. The main reason for this is that the second OData service is internal and allows more operations than the first one.
So in our controller we are basically using an OData client and let the
[EnableQuery]
do it's work:For a lot of simple functionality this is working without issue. Since
Customers
implementIQueryable
this libary can pass on most of the query parameters like $top, $skip, $orderby, etc.However, when using $expand or $select, I get exceptions, which I don't get when I replace the OData client with DBContext from EF Core:
Is there something I might be doing wrong here, or is only EF Core supported by the AspNetCoreOData project?
Beta Was this translation helpful? Give feedback.
All reactions