Databases Reference
In-Depth Information
Having the contact and address fields encapsulated in two separate entity templates, it's
time to update the main Customers entity template to instantiate them with the help of
the
DynamicEntity
control, as shown in Listing 4.8.
LISTING 4.8
Composite Customer Entity Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Customers.ascx.cs”
Inherits=”WebApplication.DynamicData.EntityTemplates.CustomerEntityTemplate” %>
<label>ID:</label>
<asp:DynamicControl runat=”server” DataField=”CustomerID” />
<asp:DynamicEntity runat=”server” UIHint=”Contact” />
<asp:DynamicEntity runat=”server” UIHint=”Address” />
Notice that because the names of the
Contact
and
Address
entity templates do not match
the name of the Customers table, you reference them explicitly by specifying the
UIHint
attribute of the
DynamicEntity
control.
If you notice, nothing is tying these new
Contact
and
Address
templates to the Customer
entity aside from the names of the fields they display. Different pages can take advantage
of the fact that
DynamicControl
performs all initialization tasks at run time by reusing
these templates for any other entity that has fields with the same names. In the
Northwind sample database, the Suppliers table is similar to the Customers table; you can
reuse both
Contact
and
Address
entity templates to implement the UI, as shown in
Listing 4.9.
LISTING 4.9
Supplier Information Page (Markup)
<%@ Page Language=”C#”
MasterPageFile=”~/Site.master” CodeBehind=”SamplePage.aspx.cs”
Inherits=”WebApplication.Samples.Ch04.GenericTemplates.SamplePage” %>
<asp:Content runat=”server” ContentPlaceHolderID=”main”>
<asp:FormView ID=”form” runat=”server” DataSourceID=”dataSource”>
<ItemTemplate>
<asp:DynamicEntity runat=”server” UIHint=”Contact” />
<asp:DynamicEntity runat=”server” UIHint=”Address” />
</ItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID=”dataSource” runat=”server”
ConnectionString=”name=NorthwindEntities” AutoGenerateWhereClause=”true”
DefaultContainerName=”NorthwindEntities”
EntitySetName=”Suppliers”
>