concept publisher in category .net

appears as: publishers, publisher, publisher, publishers
LINQ in Action

This is an excerpt from Manning's book LINQ in Action.

The listing uses a new syntax named XML literals, which is highlighted in bold. Literal means something that is output as part of the result. Here, the books, book, and publisher XML elements will be part of the generated XML. XML literals allow us to use a template of the XML we’d like to get, with a syntax comparable to ASP.

Let’s return to our web example. Let’s say we’d like to view our books sorted by publisher, then by descending price, and then by ascending title. The result would look like figure 4.16.

In the previous example, the data is collected using a projection. All the information appears at the same level. We don’t see the hierarchy between a publisher and its books. Also, there is some duplication we could avoid. For example, the name of each publisher appears several times because we’ve projected this information for each book.

Let’s look at an example to show how we can avoid projections. Let’s say we want to display publishers and their books in the same grid, as in figure 4.17.

Figure 4.17. Books grouped by publisher using nested queries

We can start by writing a query for publishers:

from publisher in SampleData.Publishers
select publisher