Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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;
GridView1.DataBind();
}

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..
Reply With Quote
  #2 (permalink)  
Old August 19th, 2011, 07:47 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.