can anyone please explain this in simple words
IQueryable
and IEnumerable
IEnumerable
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
scropio gurlPosted Jul 2, 2016, 2:24 AM
Ehsan Sajjad
Rajeesh MenothPosted Jul 1, 2016, 6:32 AM
Ehsan SajjadPosted Jul 1, 2016, 6:05 AM
scropio gurlPosted Jun 29, 2016, 3:58 AM
scropio gurlPosted Jun 29, 2016, 3:22 AM
scropio gurlPosted Jun 29, 2016, 3:17 AM
Vinay SinghPosted Jun 29, 2016, 3:10 AM
scropio gurlPosted Jun 29, 2016, 2:47 AM
Vinay SinghPosted Jun 29, 2016, 2:34 AM
IEnumerablerepresents a forward-only cursor ofT. .NET 3.5 added extension methods that included theLINQ standard query operatorslikeWhereandFirst, with any operators that require predicates or anonymous functions takingFunc.IQueryableimplements the same LINQ standard query operators, but acceptsExpression> for predicates and anonymous functions.Expressionis a compiled expression tree, a broken-up version of the method ("half-compiled" if you will) that can be parsed by the queryable's provider and used accordingly.For example:
In the first block,
x => x.Age > 18is an anonymous method (Func), which can be executed like any other method.Enumerable.Wherewill execute the method once for each person,yielding values for which the method returnedtrue.In the second block,
x => x.Age > 18is an expression tree (Expression> ), which can be thought of as "is the 'Age' property > 18".This allows things like LINQ-to-SQL to exist because they can parse the expression tree and convert it into equivalent SQL. And because the provider doesn't need to execute until the
IQueryableis enumerated (it implementsIEnumerable, after all), it can combine multiple query operators (in the above exampleWhereandFirstOrDefault) to make smarter choices on how to execute the entire query against the underlying data source (like usingSELECT TOP 1in SQL).See:
scropio gurlPosted Jun 29, 2016, 2:27 AM
IQueryable and
Vinay SinghPosted Jun 29, 2016, 2:23 AM
IQueryable :