Updated: July 2008
Represents one or multiple databases that are used by ASP.NET Dynamic Data.
Namespace:
System.Web.DynamicData
Assembly:
System.Web.DynamicData (in System.Web.DynamicData.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class MetaModel
Dim instance As MetaModel
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MetaModel
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class MetaModel
The MetaModel type lets you register one or multiple data contexts for a Dynamic Data Web application.
A data context is an object that represents a database connection. A data context has access to one data model which represents a database that is accessible through that connection. A data model is an object that represents a database's data entities as CLR types. Dynamic Data supports data models based on LINQ to SQL and on the ADO.NET Entity Framework.
In Visual Studio 2008, you can generate data-model types by using the LINQ to SQL Classes template or the ADO.NET Entity Data Model template. These templates use the Object Relational Designer (O/R Designer) for the LINQ to SQL model, or the ADO.NET Entity Data Model Designer (Entity Designer) for the Entity Framework model.
The following example shows how to use MetaModel type to perform the following tasks in order to use automatic scaffolding in an ASP.NET Web site:
Get the data model for the default data context.
Get the data model for a specified data context.
Evaluate the routing path (determine the URL) for a specified table.
The example consists of a page and its code-behind file.
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="PathModel.aspx.vb"
Inherits="PathModel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title>Path Model</title>
</head>
<body>
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
AutoLoadForeignKeys="true" />
<h3>GetActionPath</h3>
<form id="form1" runat="server">
<asp:GridView ID="GridDataSource1" runat="server"
AutoGenerateColumns="false"
DataSourceID="LinqDataSource1"
AllowPaging="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="<%#EvaluateActionPath()%>">ListDetails</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:DynamicField DataField="FirstName" />
<asp:DynamicField DataField="LastName" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
TableName="Customers"
ContextTypeName="AdventureWorksLTDataContext" >
</asp:LinqDataSource>
</form>
</body>
</html>
Imports System
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
Imports System.ComponentModel
<MetadataType(GetType(ProductMetaData))> _
Partial Public Class Product
End Class
Public Class ProductMetaData
End Class
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="PathModel.aspx.cs"
Inherits="PathModel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>Path Model</title>
</head>
<body>
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
AutoLoadForeignKeys="true" />
<h3>GetActionPath</h3>
<form id="form1" runat="server">
<asp:GridView ID="GridDataSource1" runat="server"
AutoGenerateColumns="false"
DataSourceID="LinqDataSource1"
AllowPaging="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="<%#EvaluateActionPath()%>">ListDetails</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:DynamicField DataField="FirstName" />
<asp:DynamicField DataField="LastName" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
TableName="Customers"
ContextTypeName="AdventureWorksLTDataContext" >
</asp:LinqDataSource>
</form>
</body>
</html>
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
[MetadataType(typeof(ProductMetaData))]
public partial class Product
{
}
public class ProductMetaData
{
}
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Web.DynamicData
Partial Public Class PathModel
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
DynamicDataManager1.RegisterControl(GridDataSource1)
End Sub
' Get the data model.
Public Function GetModel(ByVal defaultModel As Boolean) As MetaModel
Dim model As MetaModel
If defaultModel Then
model = MetaModel.[Default]
Else
model = MetaModel.GetModel(GetType(AdventureWorksLTDataContext))
End If
Return model
End Function
' Get the registered action path.
Public Function EvaluateActionPath() As String
Dim tableName As String = LinqDataSource1.TableName
Dim model As MetaModel = GetModel(False)
Dim actionPath As String = model.GetActionPath(tableName, System.Web.DynamicData.PageAction.List, GetDataItem())
Return actionPath
End Function
End Class
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.DynamicData;
public partial class PathModel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DynamicDataManager1.RegisterControl(GridDataSource1);
}
// Get the data model.
public MetaModel GetModel(bool defaultModel)
{
MetaModel model;
if (defaultModel)
model = MetaModel.Default;
else
model =
MetaModel.GetModel(typeof(AdventureWorksLTDataContext));
return model;
}
// Get the registered action path.
public string EvaluateActionPath()
{
string tableName = LinqDataSource1.TableName;
MetaModel model = GetModel(false);
string actionPath =
model.GetActionPath(tableName,
System.Web.DynamicData.PageAction.List, GetDataItem());
return actionPath;
}
}
To compile the example, you need the following:
Microsoft Visual Studio 2008 Service Pack 1 or Visual Web Developer 2008 Express Edition Service Pack 1.
The AdventureWorksLT sample database. For information about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database on the CodePlex site. Make sure that you install the correct version of the sample database for the version of SQL Server that you are running (Microsoft SQL Server 2005 or Microsoft SQL Server 2008).
A Dynamic Data Web site. This enables you to create a data context for the database and to create the class that contains the data field to customize and the methods to override. For more information, see Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding.
Run an online example of this feature.
System..::.Object
System.Web.DynamicData..::.MetaModel
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5 SP1
Reference
Other Resources
Date | History | Reason |
|---|
July 2008
| Added topic for new class. |
SP1 feature change.
|