Click to See Complete Forum and Search --> : All books by a certain publisher [LINQ]


rakk
February 11th, 2009, 04:38 PM
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.

eclipsed4utoo
February 11th, 2009, 07:59 PM
how would you do that in a normal SQL query?

dglienna
February 11th, 2009, 11:27 PM
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