locked
OrderBy propery trough navigation entity and projecting this property do not seems to work RRS feed

  • Question

  • I have entitty Order. Order has Customer.

    Sorting by Customer/ContactFirstName works as expected:
    /Invoicing.svc/Orders/?$inlinecount=allpages&$expand=Customer&$top=10&skip=0&$orderby=Customer/ContactFirstName asc

    Sorting by Customer/ContactFirstName and projecting just OrderNumber also works as expected:
    /Invoicing.svc/Orders/?$inlinecount=allpages&$expand=Customer&$top=10&skip=0&$select=OrderNumber&$orderby=Customer/ContactFirstName%20asc

    Projecting OrderNumber and Customer/ContactFirstName also works as expected:
    /Invoicing.svc/Orders/?$inlinecount=allpages&$expand=Customer&$top=10&skip=0&$select=OrderNumber,Customer/ContactFirstName

    Sorting by Customer/ContactFirstName and projecting OrderNumber and Customer/ContactFirstName do not work:
    /Invoicing.svc/Orders/?$inlinecount=allpages&$expand=Customer&$top=10&skip=0&$select=OrderNumber,Customer/ContactFirstName&$orderby=Customer/ContactFirstName%20asc

    This is bug?

    Result error:
    The operands for operator 'Equal' do not match the parameters of method 'op_Equality'.

    at System.Linq.Expressions.Expression.GetMethodBasedBinaryOperator(ExpressionType binaryType, Expression left, Expression right, MethodInfo method, Boolean liftToNull)

       at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method)

       at System.Linq.Expressions.Expression.MakeBinary(ExpressionType binaryType, Expression left, Expression right, Boolean liftToNull, MethodInfo method, LambdaExpression conversion)

       at System.Data.Services.Providers.BasicExpandProvider.ReplacePropertyAccessForProjectionsVisitor.VisitBinary(BinaryExpression b)

       at System.Data.Services.ExpressionVisitor.Visit(Expression exp)

       at System.Data.Services.Providers.BasicExpandProvider.ReplacePropertyAccessForProjectionsVisitor.VisitConditional(ConditionalExpression c)

       at System.Data.Services.ExpressionVisitor.Visit(Expression exp)

       at System.Data.Services.Providers.BasicExpandProvider.ReplacePropertyAccessForProjectionsVisitor.ProcessPropertyAccess(String propertyName, Expression& operandExpression, Expression& accessExpression)

       at System.Data.Services.Internal.PropertyAccessVisitor.VisitMemberAccess(MemberExpression m)

       at System.Data.Services.ExpressionVisitor.Visit(Expression exp)

       at System.Data.Services.Providers.BasicExpandProvider.ApplyOrderSkipTakeOnTopLevelResult(IQueryable query, OrderingInfo orderingInfo, Nullable`1 skipCount, Nullable`1 takeCount, ExpandNode root)

       at System.Data.Services.Providers.BasicExpandProvider.ApplyProjections(IQueryable source, ProjectionNode projection)

       at System.Data.Services.Providers.ObjectContextServiceProvider.ApplyProjections(IQueryable source, ProjectionNode projection)

       at System.Data.Services.RequestQueryProcessor.GenerateQueryResult()

       at System.Data.Services.RequestQueryProcessor.ProcessQuery()

       at System.Data.Services.RequestQueryProcessor.ProcessQuery(IDataService service, RequestDescription description)

       at System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service)

       at System.Data.Services.DataService`1.ProcessIncomingRequestUri()

       at System.Data.Services.DataService`1.HandleRequest()

    Monday, October 5, 2009 2:05 PM

Answers

  • Hello,

    Thanks for reporting this problem. It was indeed a bug in the implementation. We have already found it and fixed it. The problem was having projections ($select) and ordering on navigation property ($orderby=Customer/something) in the same query. It should work if you remove the projections from the query (the $select option). I know it's not ideal, but might work for you for now.

    Thanks again,
    Vitek Karas [MSFT]
    • Marked as answer by Mike Chaliy Tuesday, October 6, 2009 1:44 PM
    Tuesday, October 6, 2009 1:09 PM
    Moderator