1

Resolved

Sorting

description

Hi,

Considering MVC client sample when user clicks on column header in an Index view then controller composes a query like
       #region Sort
        if (!string.IsNullOrWhiteSpace(sort))
        {
            desc = sortDirection == "desc";

            // apply sorting
            query = desc ? query.OrderByDescending(p => p[sort]) : query.OrderBy(p => p[sort]);
        }
       #endregion Sort
and executes it.

When column source is value type field I am getting exception like: "Expression of type 'System.Nullable1[System.Int32]' cannot be used for return type 'System.Object'"

I did not have such issue using NTierEntityFramework 1.5, RemoteLinq 3.0, EF 5.0 but after upgrade to 1.6, 4.1.0 and 6.1.3 respectively the issue appears. Still works fine with String column types. Please advise. Thank you.

Serge.


Line 352: if (body != lambda.Body)
Line 353: {
Line 354: return Expression.Lambda(lambda.Type, body, lambda.Parameters);
Line 355: }
Line 356:

Source File: c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\ExpressionVisitorBase.cs Line: 354

Stack Trace:


[ArgumentException: Expression of type 'System.Nullable
1[System.Int32]' cannot be used for return type 'System.Object']
System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection1 parameters) +4026434
System.Linq.Expressions.Expression.Lambda(Type delegateType, Expression body, String name, Boolean tailCall, IEnumerable
1 parameters) +36
System.Linq.Expressions.Expression.Lambda(Type delegateType, Expression body, IEnumerable1 parameters) +12
Remote.Linq.ExpressionVisitors.ExpressionVisitorBase.VisitLambda(LambdaExpression lambda) in c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\ExpressionVisitorBase.cs:354
Remote.Linq.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression exp) in c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\ExpressionVisitorBase.cs:86
Remote.Linq.ExpressionVisitors.DynamicPropertyResolver.ResolveDynamicPropertySelectors(Expression expression) in c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\SystemExpressionReWriter.cs:245
Remote.Linq.ExpressionVisitors.SystemExpressionReWriter.ResolveDynamicPropertySelectors(Expression expression, Boolean throwOnInvalidProperty) in c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\SystemExpressionReWriter.cs:25
Remote.Linq.ExpressionVisitors.SystemExpressionReWriter.ResolveDynamicPropertySelectors(LambdaExpression expression, Boolean throwOnInvalidProperty) in c:\ttt\CB.Northwind\CB.Northwind\Remote.Linq\ExpressionVisitors\SystemExpressionReWriter.cs:30
NTier.Client.Domain.DataServiceQueryable.GetOrCreateRemoteExpression(LambdaExpression remoteExpression, LambdaExpression systemExpression) in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryable.cs:215
NTier.Client.Domain.Sort.get_Expression() in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryable.cs:70
NTier.Client.Domain.DataServiceQueryable.<get_ParentSortings>b__2(Sort sorting) in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryable.cs:161
System.Linq.WhereSelectEnumerableIterator
2.MoveNext() +145
System.Collections.Generic.List1..ctor(IEnumerable1 collection) +381
System.Linq.Enumerable.ToList(IEnumerable1 source) +58
NTier.Client.Domain.DataServiceQueryableImp
2.get_Query() in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryableImp.cs:43
NTier.Client.Domain.DataServiceQueryableImp2.GetEnumerator() in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryableImp.NET.cs:24
NTier.Client.Domain.OrderedDataServiceQueryable
2.GetEnumerator() in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\OrderedDataServiceQueryable.NET.cs:11
System.Linq.Buffer1..ctor(IEnumerable1 source) +204
System.Linq.Enumerable.ToArray(IEnumerable1 source) +77
NTier.Client.Domain.DataServiceQueryable
2.Execute() in c:\ttt\CB.Northwind\CB.Northwind\NTier.Client.Domain\DataServiceQueryable.NET.cs:32
CB.Northwind.Client.WebApp.Controllers.ProductController.Index(String sort, String sortDirection, Nullable
1 page) in c:\ttt\CB.Northwind\CB.Northwind\CB.Northwind.Client.WebApp\Controllers\ProductController.cs:63

comments

ChristofSenn wrote May 7, 2015 at 10:09 PM

Thanks for reporting this issue. The problem should be resolved in remote.linq

Please update to the lates version:
> update-package remote.linq