Saturday, August 20, 2011

.AsQueryable()

this post has this example:

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

IQueryable<int> iqueryable = grades.AsQueryable();

 
 

...which shows how to do casting to an IQueryable with AsQueryable(). The practical application for this comes in mocking. If a repository returns collections in IQueryable format then one will need to use this format for mocking the method call in question in testing. One may new up a List<Foo> in another class, independent of a trip to the database (no such trip required) and then cast the List<Foo> to an IQueryable<Foo>.

No comments:

Post a Comment