Hi there,
PlanetWroxEntities represents the Entity Framework context that is used to access the database and return, in this example, the Reviews. The using statement is used to create
the object and destroy at the end of the Using block. Then the query:
Code:
var allReviews = from review in myEntities.Reviews
where review.Authorized == true
orderby review.CreateDateTime descending
select review;
The review variable (following the from keyword) is called a
Range Variable. It doesn't refer to a table and you can make up its name. E.g. "r", or "myReview" or "whatever" would have worked as well. The range variable is used to refer to the object from within the query so you can filter, select and order the objects. In this example, the query looks at all reviews (since it's using myEntities.Reviews) and then filters the list to all reviews that have been authorized (e.g. where Authorized equals true). It then sorts the result set in descending order based on the CreateDateTime property. Finally, it selects the entire review by referring to the range variable. The entire query then returns a collection of Review instances which gets assigned to the allReviews variable.
If you only wanted to select each review's Title, you would have used select review.Title in which case the result set would have been a collection of strings.
In pure SQL, this would be something like:
SELECT * FROM Reviews WHERE Authorized = 1 ORDER BY CreateDateTime DESC
The Entity Framework transforms the results from this query into strongly typed Review instances.
Hope this helps,
Imar