This question is locked. New answers and comments are not allowed.
Hi,
I have a short code that add dynamically order by query to an existing query.
This code works fine on EF4.1 but doesn't work on Telerik ORM.
Here is the exception
System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
here is the linq query that been built
{Extent<XXXX.DB.Report>().Where(x => (x.inStatus == Convert(value(XXXXX.Services.Services.ReportService+<>c__DisplayClass2).statusFilter))).OrderBy(Param_0 => Param_0.Address)}
And here is the code that creates it. i think its a problem with Param_0 variable name, but this the default name when i am using the Parameter expression.
I have a short code that add dynamically order by query to an existing query.
This code works fine on EF4.1 but doesn't work on Telerik ORM.
Here is the exception
System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
here is the linq query that been built
{Extent<XXXX.DB.Report>().Where(x => (x.inStatus == Convert(value(XXXXX.Services.Services.ReportService+<>c__DisplayClass2).statusFilter))).OrderBy(Param_0 => Param_0.Address)}
And here is the code that creates it. i think its a problem with Param_0 variable name, but this the default name when i am using the Parameter expression.
public IQueryable<T> ApplyOrder(IQueryable<T> source) { var sortOrder = (_sortOrder == SortOrder.Ascending) ? "OrderBy" : "OrderByDescending"; ParameterExpression[] parameters = new ParameterExpression[] { Expression.Parameter(typeof(T)) }; //Dig into lambda expression Type fieldType = null; MemberExpression memberExpression = null; Type t = typeof(T); string[] tokenFieldName = _orderByField.Split('.'); foreach (var s in tokenFieldName) { var properties = TypeDescriptor.GetProperties(t); var property = properties[s]; if (property != null) { t = fieldType = property.PropertyType; if (memberExpression == null) { memberExpression = Expression.Property(parameters[0], s); } else { memberExpression = Expression.Property(memberExpression, s); } } else { throw new Exception(string.Format("Cannot find field with name '{0}'", _orderByField)); } } if (memberExpression != null) { Expression queryExpr = Expression.Call( typeof(Queryable), sortOrder, new Type[] { typeof(T), fieldType }, source.Expression, Expression.Quote(Expression.Lambda(memberExpression, parameters))); source = source.Provider.CreateQuery<T>(queryExpr); return source; } else { throw new NullReferenceException("No memberExpression was constructed"); } }