Databases Reference
In-Depth Information
Creating an Entity Template
Entity Template is a special type of user control used by Dynamic Data to encapsulate
presentation logic for a single entity or a class that represents a single row from a database
table. You can create a custom entity template for the Customers table by simply extract-
ing the highlighted code from Listing 4.1 and placing it into a new user control,
Customers.ascx , in the DynamicData\EntityTemplates folder of the web project, which is
where Dynamic Data looks for entity templates by default. Listing 4.3 shows markup of
the new entity template.
LISTING 4.3
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” />
<label>Name:</label>
<asp:DynamicControl runat=”server” DataField=”ContactName” />
<fieldset><legend>Address</legend>
<label>Street:</label>
<asp:DynamicControl runat=”server” DataField=”Address” /><br />
<label>City:</label>
<asp:DynamicControl runat=”server” DataField=”City” />
<label>State:</label>
<asp:DynamicControl runat=”server” DataField=”Region” />
<label>Zip:</label>
<asp:DynamicControl runat=”server” DataField=”PostalCode” />
</fieldset>
Aside from the <%@ Control %> directive, markup of the new Customers entity template is
a true copy and paste of the code from Listing 4.1.
NOTE
Note that the name of the control file, Customers.ascx, is significant. The file name,
without extension, needs to match the name of the MetaTable that describes the
Customer entity in the metadata, which is Customers (plural).
The user control must inherit from a special class provided by the Dynamic Data, called
EntityTemplateUserControl , as shown in Listing 4.4. This simple base class provides
several properties, including Table , which returns a MetaTable instance describing the
entity and Mode , which could be Read Only, Insert, or Edit.
 
 
Search WWH ::




Custom Search