Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Func with IQueryable that returns IOrderedQueryable

Tags:

linq

I'm doing some research about EF and came across a function that accepts

Func<IQueryable<Student>, IOrderedQueryable<Student>> 

and just wondering how to call that function that accepts that kind of parameter?

like image 337
RyanMAd Avatar asked Feb 08 '13 15:02

RyanMAd


1 Answers

imagine function is something like that, and you've got a property Id in Student class.

public static class Helper {
    public static void Test(Func<IQueryable<Student>, IOrderedQueryable<Student>> param)
        {
            var test = 0;
        }
}

then you could use it this way

var student = new List<Student>().AsQueryable();//non sense, just for example
Helper.Test(m => student.OrderBy(x => x.Id));

m => student.OrderBy(x => x.Id) is a

Func<IQueryable<Student>, IOrderedQueryable<Student>>

(IQueryable<student> as parameter, returning a IOrderedQueryable<Student>)

or just

Helper.Test(m => m.OrderBy(x => x.Id));

In fact this doesn't make much sense without a "real" function...

like image 87
Raphaël Althaus Avatar answered Oct 13 '22 04:10

Raphaël Althaus