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