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 April 3rd, 2011, 08:39 PM
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to display only authorized reviews

Currently, Reviews/Default.aspx and Reviews/AllByGenre.aspx as presented in the Try It Out sections (at least as of Chapter 18--I haven't quite finished the book yet) display all reviews, whether or not the Authorized bit is set. Is there a way to rearrage the LINQ query to exclude unauthorized reviews? This query, from Reviews/Default.aspx, is as close as I've been able to come, but the join flattens the hierarchical data, so the output contains duplicate Genre headings.

Code:
        var favGenres = from genre in myEntities.Genres
                        join review in myEntities.Reviews on genre.Id equals review.GenreId
                        where Profile.FavoriteGenres.Contains(genre.Id) 
                          && (genre.Reviews.Count() > 0) 
                          && (review.Authorized == true)
                        orderby genre.Name
                        select new { genre.Name, genre.Reviews };
If I remove the join, I get an error from the "review.Authorized == true" condition that the name "review" does not exist in the current context, which makes sense because it "review" is defined in the join. Substituting "myEntities.Reviews.Authorized == true" with the "join" removed also results in an error. Should I be using some sort of subquery here?

Thanks very much in advance,
Jeff
 
Old April 4th, 2011, 02:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can add a Where clause to your select statement for the reviews. You can see a VB example here: Authorized reviews

Hope this helps, but if it doesn't, please let me know.

Cheers,

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!
The Following User Says Thank You to Imar For This Useful Post:
jtcours (April 5th, 2011)
 
Old April 5th, 2011, 01:06 AM
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

. . . and the student was enlightened. This:

Code:
select new { genre.Name, Reviews = genre.Reviews.Where (r => r.Authorized == true) };
did the trick. Thanks very much for the help!
 
Old April 5th, 2011, 03:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yep, that's exactly what you need.....

Cheers,

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4:Displaying the reviews p.126-128 drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 6 November 6th, 2010 04:04 AM
Authorized reviews sophia BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 11 October 6th, 2010 07:56 AM
Reviews jack_hilary BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 May 23rd, 2010 03:55 PM
problems with the reviews table in chapter 4 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 15th, 2007 03:58 AM
I've read some bad reviews; what do readers think? disruptivehair BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 11 January 18th, 2006 04:44 PM





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