Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 19th, 2011, 05:01 AM
Registered User
Join Date: Aug 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 14 ado.net

I am looking for a breakdown of this statement that is in first example of chapter 14.
QUickly chapter 14 has gotten over my head it seems as i dont understand teh formats of the queries.
i take it planetwroxentities is the class for the ado.net.
How owuld this statement look in standard sql is what i am wondering.
it is really the first line that confuses me" var allReviews = from review in myEntities.Reviews "
and teh last line databind method.

using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
var allReviews = from review in myEntities.Reviews
where review.Authorized == true
orderby review.CreateDateTime descending
select review;
GridView1.DataSource = allReviews;

also here is anotehr example in teh book on page 487

var allReviews = from r in myEntities.Reviews
select r;

wtf. R should be a table but it is also a sleect column. Does r jsut represent *?i dont udnerstand the explanation in book

Last edited by zedjr; August 19th, 2011 at 05:27 AM..
Old August 19th, 2011, 07:47 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

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:

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 Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 - ADO.NET Entity Data Model Sean1980 BOOK: Beginning ASP.NET 4 : in C# and VB 3 July 15th, 2011 12:24 PM
Chapter 14 ASP.Net 4.0 fredfenk BOOK: Beginning ASP.NET 4 : in C# and VB 0 April 8th, 2011 01:07 PM
Chapter 14 Linq and ado.net entity framework pandukal21 BOOK: Beginning ASP.NET 4 : in C# and VB 8 January 28th, 2011 05:19 AM
question for ADO.NET chapter 14 stram BOOK: Beginning ASP.NET 4 : in C# and VB 6 September 27th, 2010 06:44 AM
Chapter 14 example pkumar@ech BOOK: Professional Jakarta Struts 0 November 15th, 2006 09:10 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.