本文介绍了类型“ Queryable”上的通用方法“ OrderBy”与提供的类型参数不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些将修改表达式的代码,以使其中包含的子查询得到排序。



我发现了类似的一段代码,但这对我不起作用。我还尝试查看答案,但是我'无法将其应用于我的代码



  MethodCallExpression orderByCallExpression =表达式.Call(
typeof(Queryable),
OrderBy / *降序* /,
new Type [] {typeof(TSource),filterpart.OrderOverPropertyGetterValueType},
navigationalProperty。正文,
filterpart.OrderOverPropertyGetter);

我正在尝试找出2个类型参数或其他2个参数中的哪个导致此错误。




  • OrderOverPropertyGetterValueType 只是 typeof(DateTime)在这种
    情况下

  • TSource 是实体类型(礼物

  • navigationalProperty.Body 包含{ source.Gifts.AsQueryable() },其表达式类型为: System.Linq.Expressions.MethodCallExpression

  • filterpart .OrderOverPropertyGetter 包含 {g => g.Date} ,表达式类型为 System.Linq.Expressions.Expression< System.Func< Gift,System.DateTime>>>



我不知道如何诊断四个参数中的哪个不正确。我认为其中一种表达式类型可能不正确。

解决方案

由于错误提示,我的类型定义错误。 / p>

typeof(TSource)必须为 typeof(TNav),因为我们要订购 source.Gifts


I'm writing some code that will modify an expression so that the subquery contained in it will get ordered.

I found a similar piece of code here on SO, but it's not working for me. I also tried looking at this answer, but I'm not able to apply this to my piece of code

MethodCallExpression orderByCallExpression = Expression.Call(
    typeof(Queryable),
    "OrderBy"/*Descending*/,
    new Type[] { typeof(TSource), filterpart.OrderOverPropertyGetterValueType },
    navigationalProperty.Body,
    filterpart.OrderOverPropertyGetter);

I'm trying to figure out which of the 2 type parameters or 2 other arguments is causing this error.

  • OrderOverPropertyGetterValueType is just typeof(DateTime) in thiscase
  • TSource is an Entity Type (Gifts)
  • navigationalProperty.Body contains {source.Gifts.AsQueryable()} with expression type: System.Linq.Expressions.MethodCallExpression
  • filterpart.OrderOverPropertyGetter contains {g => g.Date} with expression type System.Linq.Expressions.Expression<System.Func<Gift,System.DateTime>>

I'm clueless how to diagnose which of the four parameters is incorrect. I'm thinking one of the expression types may be incorrect.

解决方案

My type definitions were wrong, as the error suggested.

typeof(TSource) had to be typeof(TNav), since we are ordering source.Gifts.

这篇关于类型“ Queryable”上的通用方法“ OrderBy”与提供的类型参数不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 06:41