What is difference between IEnumerable and IQueryable?

There are following differences between ADO.NET and Entity Framework: IEnumerable IQueryable Exists in System.Collections Namespace Exists in System.Linq Namespace Best to query data from in-memory collections like List, Array etc. Best to query data from out-memory (like remote database, service) collections. While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. For Example:

Generated SQL having no Top Keyword:

While querying data from database, IQueryable execute select query on server side with all filters. For Example:

Generated SQL having Top Keyword:

Suitable for LINQ … Click here to continue…..

How LINQ query is compiled to Expression Trees?

In LINQ, a query expression is compiled to expression trees or to delegates, depending on the type that is applied to query result. The IEnumerable<T> type LINQ queries are compiled to delegates and IQueryable or IQueryable<T> type LINQ queries are compiled to expression trees. In short, LINQ queries that execute in process are compiled into delegates while the queries that execute out of process are compiled into expression trees. In LINQ, domain-specific queries (like LINQ to SQL, LINQ to Entity) are result into IQueryable<T> type. The C# and Visual Basic compilers compile these queries into code that builds an expression … Click here to continue…..

How Expressions Trees are different from Lambda Expression?

A common misunderstanding is that expression trees are identical to lambda expressions. But this is not true since you can also create and modify expression trees by using API methods i.e. without using lambda expression syntax at all. Also, every lambda expression cannot be implicitly converted into an expression tree. Only expression lambda is implicitly converted an expression tree and statement lambda i.e. multi-line lambda cannot be implicitly converted into expression tree.

How can you create Expression Trees?

You can create expression trees by using following two ways: Using Expression Lambda – The easiest way to generate an expression tree is to create an instance of the Expression<T> type, where T is a delegate type, and assign a lambda expression to this instance.

In this example, the C# compiler generates the expression tree from the provided lambda expression. This looks much more complicated, but this is what actually happens when you supply a lambda expression to an expression tree. The structure of above expression trees will be like as: Using Expression Tree API – Expression class is … Click here to continue…..

What is Expression Trees?

Expression Trees was first introduced in C# 3.0 (Visual Studio 2008), where they were mainly used by LINQ providers. Expression trees represent code in a tree-like format, where each node is an expression (for example, a method call or a binary operation such as x < y). You can also convert expression trees into compiled code and run it. This transformation enables dynamic modification of executable code as well as the execution of LINQ queries in various databases and the creation of dynamic queries.