Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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 October 9th, 2010, 07:20 PM
Authorized User
 
Join Date: Oct 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with Queries and Anonymous Types

In BegAsp 3.5 The 'Genre - Review' TryOut query offers up a collection of reviews for each genre. Can you access sub-collections of collections?

For example: Genre > Review (collection) > UserComment (collection)?

Attempts on my own similarly structured data have failed.

Regards, Guy

-------

var allGenres = from genre in myDataContext.Genres
orderby genre.Name
select new { genre.Name, genre.Reviews };
 
Old October 10th, 2010, 03:12 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 don't need to query them separately; each Review already contains a reference to its associated UserComments. The following should work and displays all comments for all reviews:

Code:
var allGenres = from genre in myDataContext.Genres
                orderby genre.Name
                select new { genre.Name, genre.Reviews };
 
foreach (var genre in allGenres)
{
  foreach (var review in genre.Reviews)
  {
    foreach (var userComment in review.UserComments)
    {
      string comment = userComment.Comment;
    }
  }
}
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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13:page 439,Queries and Anonymous types Arya BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 February 2nd, 2010 11:22 PM
Anonymous Shopping Cart Greathouse BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 17th, 2009 12:57 PM
About Anonymous Identification Lee Dumond BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 15 December 14th, 2008 05:12 PM
Combining Queries or results from 2 queries Ford SQL Server 2000 24 November 7th, 2005 08:54 PM
Session not working for Anonymous users songsan General .NET 0 January 4th, 2005 02:57 PM





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