in Education by
Im using EntityFramework Code First Generic Repository. I have one filter method. Also this method make paging and sorting. Method like below public IQueryable Filter(Expression> filter, out int total, Expression> sorting, SortType sortDirection, int index = 1, int size = 30) { index = index - 1; int skipcount = index * size; IQueryable resetSet = filter != null ? Entities.Where(filter) : Entities.AsQueryable(); total = Entities.Where(filter).Count(); if (sortDirection == SortType.Desc) { resetSet = skipcount == 0 ? resetSet.Where(filter).OrderByDescending(sorting).Skip(0).Take(size) : resetSet.Where(filter).OrderByDescending(sorting).Skip(skipcount).Take(size); } else { resetSet = skipcount == 0 ? resetSet.Where(filter).OrderBy(sorting).Skip(0).Take(size) : resetSet.Where(filter).OrderBy(sorting).Skip(skipcount).Take(size); } return resetSet.AsQueryable(); } Type of sorting is Expression> If i pass this parameter as Expression> getting an exception invalid casting between int to object but Expression> dosent throw any exception.. Any idea Thanks JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Type of sorting is Expression> If i pass this parameter as Expression> getting an exception invalid casting between int to object but Expression> dosent throw any exception.. That's because int is a value type, while string is a reference type. An int needs to be boxed to be converted to object, and the Linq Expression API doesn't do it automatically. When you generate the expression, if you return an int, you need to add an Expression.Convert(, typeof(object)) around the expression before you return it.

Related questions

0 votes
    I am trying to update an Entity EF Core record like this: public class Customer { public int Id { ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    How can an int be cast to an enum in C#?...
asked Jan 15, 2021 in Technology by JackTerrance
0 votes
    I am developing Outlook add-ins which populates all the available shared mailboxes in to combo box and sends ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am developing Outlook add-ins which populates all the available shared mailboxes in to combo box and sends ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I want to convert the matched expression in string or int. But in .NET Framework I do not find ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    a,b,c and d are int type, however, the expression is slightly modified as (a+b*c-d)/7.0. ... of the following mathematical expression? Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    a,b,c and d are int type, however, the expression is slightly modified as (a+b*c-d)/7.0. ... of the following mathematical expression? Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    What is the value of m after evaluating the following expression:m -= 9%++n + ++n/2; when int m=10,n=6. Pls Answer Now.. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    do you think the following two expression are the same if yes write the output if not justify your answer X=int(22/7) X=(22.0/7) Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    An expression involving byte, int, and literal numbers is promoted to which of these? (a) int (b) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    If an expression contains double, int, float, long, then the whole expression will be promoted into which of ... questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    Q.32 :-What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? ... y); return 0; Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Find the expression of f (t) in the graph shown below. (a) 10t [u (t) - u (t - 1)] - (- ... theory Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    In the graph shown below, find the expression f (t). (a) 2t (b) 3t (c) 4t (d) 5t I have been ... theory Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    Let us assume x (t) = A cos(ωt + φ), what is the s-domain expression? (a) Y(s)=H(s) A( ... Network theory Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
...