Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between IQueryable and Queryable

Tags:

c#

I haven't quite got my head around interfaces so thought I'd word the question in a way that'd help me better understand it.

I'm following a tutorial which has had me make an IQueryable. Why couldn't I just make a Queryable?

like image 641
SexyProgrammer Avatar asked Apr 19 '26 04:04

SexyProgrammer


2 Answers

Queryable is just a static class that contains extension methods to the IQueryable<T> interface. You wouldn't use Queryable directly in your code but rather invoke its methods given an IQueryable<T> instance.

like image 98
Darin Dimitrov Avatar answered Apr 21 '26 17:04

Darin Dimitrov


Queryable is a static class that provides some convenient and useful methods to anything implementing IQueryable. You can't make it because it's already made. You need to make a new class that actually does what you want it to do, and implement IQueryable so other code written to use IQueryable (including Queryable) knows how to use it.

like image 44
Jon Hanna Avatar answered Apr 21 '26 17:04

Jon Hanna