CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    12

    All books by a certain publisher [LINQ]

    Sorry for asking again but this is important for me:

    I have two tables:
    [publishers](
    [pub_id] [char](4) NOT NULL,
    [pub_name] [varchar](40) NULL,
    [city] [varchar](20) NULL,
    [state] [char](2) NULL,
    [country] [varchar](30) )

    and

    [titles](
    [title_id] [dbo].[tid] NOT NULL,
    [title] [varchar](80) NOT NULL,
    [type] [char](12) NOT NULL DEFAULT ('UNDECIDED'),
    [pub_id] [char](4) NULL,
    [price] [money] NULL,
    [advance] [money] NULL,
    [royalty] [int] NULL,
    [ytd_sales] [int] NULL,
    [notes] [varchar](200) NULL,
    [pubdate] [datetime] NOT NULL

    How can I get all the books from a certain publisher in one linq query:

    The result should be something like that
    Publisher 1
    book1
    book2
    ..
    Publisher 2
    book1
    book2
    ..

    I am a bit new to LINQ and I don't quite handle it well.
    The tables above are from Nothhwind, so I am learning on them.

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: All books by a certain publisher [LINQ]

    how would you do that in a normal SQL query?

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: All books by a certain publisher [LINQ]

    Why only one statement? LINQ is powerful, but you don't have to make it one-line.

    I'd create the list of authors, and then query the books table for each author in the first list. you can order in each one.

    You'd loop thru both tables to output
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured