Comparing LINQ to Entities with LINQ to Objects
In the previous chapter, we used LINQ to query in-memory objects. Before we dive further into the world of LINQ to Entities we first need to look at the relationships between LINQ to Entities and LINQ to Objects.
Some key differences between LINQ to Entities and LINQ to Objects are:
LINQ to Entities needs an Object Context object. The
ObjectContext
object is the bridge between LINQ and the database (we will explain more aboutObjectContext
later). LINQ to Objects doesn't need any intermediate LINQ provider or API.LINQ to Entities returns data of type,
IQueryable<T>
, whereas LINQ to Objects returns data of type,IEnumerable<T>
.LINQ to Entities queries are translated to SQL by way of Expression Trees, which allow them to be evaluated as a single unit and translated to appropriate and optimal SQL Statements. LINQ to Objects queries do not need to be translated.
LINQ to Entities queries are translated to SQL calls and executed on the...