Differences between

IQueryable Inherited fromIEnumerable

IEnumerable:IEnumerable<T> Generic classes are calling their ownSKip and Take
The data will be loaded in the local memory before some extension methods, All forIEnumerable Filtration, Sorting and other operations, It's all in memory.

IQueryable:IQueryable<T>
Is to translate these method expressions intoT-SQL Backward directionSQL Server sends command, It does not load all data into memory for conditional filtering,IQueryable The advantage is that it has an expression tree, All forIQueryable Filtration, Sorting and other operations, Will be cached in the expression tree first, Only when real traversal happens, The expression tree will beIQueryProvider Perform get data operation( Analytic expression, Then execute to get results).

 

Use environment

Usually in the data access layer
UseIQueryable, Because it can delay the loading of data to the business logic layer, Many times, Business logic layer does not need to load data immediately, The business logic layer can still use delay loading, When it's really necessary to load data, Can be converted toIEnumerable