Reputation: 20304
Using Entity Framework 4, and given:
ObjectSet<Thing> AllThings = Context.CreateObjectSet<Thing>;
public IQueryable<Thing> ByNameA(String name)
{
IQueryable<Thing> query = from o in AllThings
where o.Name == name
select o;
return query;
}
public IQueryable<Thing> ByNameB(String name)
{
return AllThings.Where((o) => o.Name == name);
}
Both return IQueryable<> instances, and thus the query doesn't hit the server until something like ToList()
is called, right? Is it purely readability that is the difference, or are the using fundamentally different technologies on the back-end?
Upvotes: 1
Views: 508
Reputation: 564413
These compile to nearly identical code.
The first syntax translates directly, by the compiler, into methods with the names provided in the second syntax.
The main difference between these two methods is really just that you're using a different syntax, and that you're assigning to a temporary variable (query) instead of just returning the result directly. However, they are, for all practical purposes, identical.
Upvotes: 1