Export (0) Print
Expand All

MetaModel Class

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)

Public Class MetaModel

The MetaModel type exposes the following members.

Public methodMetaModelInstantiates a new instance of the MetaModel class.
Public methodMetaModel(Boolean)Instantiates a new instance of the MetaModel class.

Public propertyStatic memberDefaultGets the first instance of a data model that is created by the application.
Public propertyDynamicDataFolderVirtualPathGets or sets the virtual path of the DynamicData folder in the Web site.
Public propertyEntityTemplateFactoryGets or sets the EntityTemplateFactory object that is associated with the model.
Public propertyFieldTemplateFactoryGets or sets a custom IFieldTemplateFactory interface.
Public propertyFilterFactoryGets or sets the FilterFactory object that is associated with the model.
Public propertyTablesGets a collection of all the tables that are part of the data model.
Public propertyVisibleTablesGets a collection of the visible tables in the data model.

Protected methodCreateTableInstantiates a MetaTable object.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetActionPathReturns the action path that is associated with a specific table.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodStatic memberGetModelReturns the data-model instance for the specified context.
Public methodGetTable(String)Returns the metadata that is associated with the specified table.
Public methodGetTable(Type)Returns the metadata that describes the specified table.
Public methodGetTable(String, Type)Returns the metadata that describes the specified table.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRegisterContext(DataModelProvider)Registers a data context instance by using a data-model provider
Public methodRegisterContext(Func(Of Object))Registers the data context that is specified by a context factory.
Public methodRegisterContext(Type)Registers a data-context instance.
Public methodRegisterContext(DataModelProvider, ContextConfiguration)Registers a data-context instance by using the specified context configuration and by enabling a data-model provider.
Public methodRegisterContext(Func(Of Object), ContextConfiguration)Registers a data-context instance by using the specified context configuration and by enabling a custom constructor.
Public methodRegisterContext(Type, ContextConfiguration)Registers a data-context instance by using the specified context configuration.
Public methodStatic memberResetRegistrationExceptionResets any previous context registration error that might have occurred.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTryGetTable(String, MetaTable)Attempts to get the metadata that is associated with the specified table.
Public methodTryGetTable(Type, MetaTable)Attempts to get the metadata that is associated with the specified table.


Can be thrown by any method if there has been a data context registration error.

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 available 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, 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" 
Inherits="PathModel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Path Model</title>
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />


    <form id="form1" runat="server">
        <asp:GridView ID="GridDataSource1" runat="server"
            <asp:HyperLink ID="HyperLink1" runat="server" 
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />

        <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        ContextTypeName="AdventureWorksLTDataContext" >

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
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

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)
    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]
            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

To compile the example, you need the following:

See a run-time code example of this feature: Run.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2014 Microsoft