c# - How to Cast Expression Func<T,int> to Func<T,object> -
I am using EntityFramework code first generic repository. I have a filter method, besides this method paging and sorting Are there. The method like
public IQueryable & lt; TENTity & gt; Filters (expression & quot; throw & lieutenant; tantity, ball & gt; & gt; filter, integer complete, expression & lt; funk & gt; tmente, object & gt; sorted, sort sort sort direction, int index = 1 , Int size = 30) {index = index-1; Int skipcount = index * size; IQueryable & LT; TEntity & gt; Resetset = Filter! = Null? Institutions Where (Filter): Institutions. Enqueueable (); Total = body Where (filter). Country (); If (sortDirection == SortType.Desc) {resetSet = skipcount == 0? Resetset Where (filter). Orderbasedseeding (sorting). Skip (0). Move (Size): Resetset Where (filter). Orderbinding (sorting) .cip (skikount). Move (shape); } And {resetSet = skipcount == 0? Resetset Where (filter). Order by (sorting). Leave (0). Take (shape): Resetset Where (filter). Order by (sorting). Skipcount Move (shape); } Return Resetset. Absolutely (); }
Sorting type Throw any exception Thanks to any idea code> if I get this parameter to be expression and lieutenant; Function lift; Object, object & gt; & Gt;
If I give this parameter the expression> lt; Funk & lt; TENTity, object & gt;
sorting type expression & lt; Func & lt; TEntity, Object & gt; & Gt;
expression & lt; Func & lt; TENTity, Object & gt; & Gt; I pass this parameter as
, then an exception between the object invalid casting but the expression
int
is a value type, because string
is a reference type object
, there should be a int
boxed, and the Linq Expression
API does not automatically do this if you If you return int
, then you need to add an expression. Conversion (& lt; expr & gt ;, typeof (object))
return it.
Comments
Post a Comment