Databases Reference
In-Depth Information
In data models that use inheritance, derived entity classes are represented slightly differ-
ently. Imagine a CRM (Customer Relationship Management) system that has a base class
Contact
and derived classes
Prospect
and
Customer
. Even though both Prospect and
Customer entities might be stored in the same database table called Contacts, Dynamic
Data provides a separate
MetaTable
object for each entity class. The name of each
MetaTable
matches the name of the derived class, so for the Prospect entity, the
MetaTable
name and the default template name is
Prospect
, singular:
using (CrmEntities context = new CrmEntities())
{
var prospects = from p in context.Contacts.OfType<
Prospect
>()
select p;
}
Template name can also be specified explicitly by setting the
UIHint
attribute of the
DynamicEntity
control, in which case it does not have to match the table name of the
entity class at all:
<asp:DynamicEntity runat=”server” UIHint=”Contact”/>
An explicitly specified template name is a more specific match than the
table
name.
Therefore, if the previous code snipped is used for the Customer entity, the
Contact.ascx
entity template is used even though the
Customers.ascx
entity template is also available.
If a matching template cannot be found based explicitly on the specified template name
or the table name,
Default
is used. Because Dynamic Data projects come with a set of
default entity templates out of the box, this guarantees that a matching template exists for
any entity.
Template Mode
Similar to the control mode for field templates, template mode defines the context where
the entity template will be used. It is defined by the members of the ASP.NET
DataBoundControlMode
enumeration and used by Dynamic Data to determine the suffix of
the template file name:
.
ReadOnly
templates are used to implement the
ItemTemplate
of the
FormView
and
ListView
controls. Read-only entity templates have no mode-based suffix in their
file names.
.
Edit
templates are used to implement the
EditItemTemplate
of the
FormView
and
ListView
controls. Edit templates have
_Edit
at the end of their file names, such as
Default_Edit.ascx
.
.
Insert
templates are used to implement
InsertItemTemplate
of the
FormView
and
ListView
controls and have
_Insert
at the end of their file names, such as
Default_Insert.ascx
.