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

Instance property 'Values' is not defined for type 'System.Object' (Parameter 'propertyName') #2742

Open
joamla96 opened this issue Jan 3, 2023 · 3 comments
Assignees

Comments

@joamla96
Copy link

joamla96 commented Jan 3, 2023

Attempting to group-by and aggregate results in Expression Exception

Assemblies affected

  • Microsoft.AspNetCore.OData 8.0.12

Expected result

List of results

Actual result

Exception

Additional detail

Query: GET https://localhost:5041/odata/FutureCart?$apply=groupby((CatalogueId, ScheduledProvisioning/PartnerId, ScheduledProvisioning/State),aggregate(Quantity with sum as TotalQuantity))

Logged Exception:

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.ArgumentException: Instance property 'Values' is not defined for type 'System.Object' (Parameter 'propertyName')
         at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
         at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.GetPropertyExpression(Expression source, String propertyPath, Boolean isAggregated)
         at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.CreatePropertyAccessExpression(Expression source, QueryBinderContext context, IEdmProperty property, String propertyPath)
         at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.BindPropertyAccessQueryNode(SingleValuePropertyAccessNode propertyAccessNode, QueryBinderContext context)
         at Microsoft.AspNetCore.OData.Query.Expressions.OrderByBinder.BindOrderBy(OrderByClause orderByClause, QueryBinderContext context)
         at Microsoft.AspNetCore.OData.Query.Expressions.BinderExtensions.ApplyBind(IOrderByBinder binder, IQueryable query, OrderByClause orderByClause, QueryBinderContext context, Boolean alreadyOrdered)
         at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.AddOrderByQueryForProperty(IOrderByBinder orderByBinder, OrderByClause orderbyClause, IQueryable querySoFar, QueryBinderContext binderContext, Boolean alreadyOrdered)
         at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.ApplyToCore(IQueryable query, ODataQuerySettings querySettings)
         at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
         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()

Controller Setup:

namespace ODataApiTest.Controllers.Odata
{
    [Produces("application/json")]
    [Authorize]
    public class FutureCartController : ODataController
    {
        private readonly DatabaseContext _context;
        private readonly ScopeData _scopeData;

        public FutureCartController(DatabaseContext context, ScopeData scopeData)
        {
            _context = context;
            _scopeData = scopeData;
        }

        [EnableQuery(PageSize = 250)]
        public IQueryable<FutureCartItem> Get()
        {
            if (!_scopeData.User.HasPermission(DTO.PermissionNode.isAdmin))
                throw new Exception("Permission Denied"); // TODO Proper exception

            var baseQuery = _context.FutureCartItem;
            return baseQuery;
        }
    }
}

Relevant Startup parts:

 var modelBuilder = new ODataConventionModelBuilder();
            
var cartLine = modelBuilder.EntitySet<FutureCartItem>("FutureCart");
var scheduleProvisionings = modelBuilder.EntitySet<ScheduledProvisioning>("ScheduledProvisioning");

scheduleProvisionings.EntityType.Ignore(x => x.Error);
scheduleProvisionings.EntityType.Ignore(x => x.Trys);
services.                
    .AddControllers()
    .AddOData(options => options.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null).AddRouteComponents("odata", modelBuilder.GetEdmModel()))

Relevant Models:

public class FutureCartItem : Entity
{
    public string Sku { get; set; }
    public int Quantity { get; set; } 
    public bool AutoRenew { get; set; }
    public Guid ScheduledProvisioningId { get; set; }
    public ScheduledProvisioning ScheduledProvisioning { get; set; }
    public Guid CatalogueId { get; set; }
}

public abstract class ScheduledTransaction : Entity
{
    public Guid PartnerId { get; set; }    
    public Guid CustomerId { get; set; }
    public string PlacedByUser { get; set; }
    public DateTime PlacedAtUtc { get; set; }
    public DateTime ScheduledFor { get; set; }
    public DateTime? ProcessingStartedAtUtc { get; set; }
    public DateTime? ProcessingEndedAtUtc { get; set; }
    public ScheduledState State { get; set; } = ScheduledState.Unprocessed;
    public ScheduledTransactionError Error { get; set; }
    public ScheduledTransactionType Type { get; set; }
    public int Trys { get; set; }
}

public class ScheduledProvisioning : ScheduledTransaction
{
    public List<FutureCartItem> CartLines { get; set; }
}

public abstract class Entity
{
    public Guid Id { get; set; }
}
@gathogojr gathogojr self-assigned this Jan 3, 2023
@gathogojr
Copy link
Contributor

Hi @joamla96. Thank you for reporting the issue. Unfortunately I'm not able to reproduce it based on the provided details - in spite of my best effort. Can you share a simple repro that we can use to investigate the issue?

@joamla96
Copy link
Author

joamla96 commented Jan 6, 2023

Hi @gathogojr

Thank you for your time!

I've taken our application, and stripped away everything unrelated. Ill attach it here.

I was still able to reproduce the issue with this code, and the following URI:
https://localhost:5041/odata/FutureCart?$apply=groupby((CatalogueId, ScheduledProvisioning/PartnerId, ScheduledProvisioning/State),aggregate(Quantity with sum as TotalQuantity))

CF.Microsoft.zip

@pksorensen
Copy link

pksorensen commented Mar 17, 2023

I hit the same exception on following odata:

https://local-mc-portal:44396/api/entities/smsmessages?pretty&$apply=groupby((Customer/User/id,Customer/User/Name)%20,aggregate($count%20as%20smsmessages))&$top=20

however with out the $top it works

odata 8.0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants