Databases Reference
In-Depth Information
The first example is a page that displays a list of items a customer previously ordered from
the Northwind Traders website. For each item, the page displays name of the product,
quantity, date of the order, and the order status. You can see how this page will look in
Figure 12.1. Of course, in a real-world application, this page might also allow users to
reorder items by clicking a link or selecting a check box next to each item. However, to
keep the example simple, this particular functionality is not implemented.
FIGURE 12.1
List page with columns from multiple related entities.
This page displays properties of three related entities: Order_Detail, Product, and Order. As
you can see by looking at the Northwind entity model, the Order_Detail entity has two
foreign key
(also known as
navigation
) properties called Product and Order that point to the
respective parent entities. On the sample page in the figure, the first column displays the
ProductName
property of the parent Product entity, and the last two columns display the
OrderDate
and
OrderStatus
properties of the parent Order entity.
Consider how this page could be implemented with the built-in controls and field
templates provided by Dynamic Data. For the
ProductName
, you could have used the
built-in
ForeignKey
field template, which would display product names as hyperlinks.
However, there is no way to display both
OrderDate
and
OrderStatus
using just the field
templates that Dynamic Data offers out of the box. The
ForeignKey
field template can
display value of only one property, the one specified in the
DisplayColumnAttribute
applied to the parent entity class, so you could display either the
OrderDate
or the
OrderStatus
, but not both.
To solve this problem, the sample solution includes a new field template called Parent (for
consistency with the built-in Children template). This template can be used with foreign
key columns and allows you to set the
DisplayField
attribute to any column from the
parent entity to display. Following is an example of using this template with the
Order
property of the Order_Detail entity to display the
OrderDate
property of the parent Order
entity. Listing 12.4 later in this section shows a complete markup of the sample page.