MetaModel Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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


Instantiates a new instance of the MetaModel class.


Instantiates a new instance of the MetaModel class.


Gets the first instance of a data model that is created by the application.


Gets or sets the virtual path of the DynamicData folder in the Web site.


Gets or sets the EntityTemplateFactory object that is associated with the model.


Gets or sets a custom IFieldTemplateFactory interface.


Gets or sets the FilterFactory object that is associated with the model.


Gets a collection of all the tables that are part of the data model.


Gets a collection of the visible tables in the data model.


Instantiates a MetaTable object.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetActionPath(String, String, Object)

Returns the action path that is associated with a specific table.


Serves as the default hash function. (Inherited from Object.)


Returns the data-model instance for the specified context.


Returns the metadata that is associated with the specified table.

System_CAPS_pubmethodGetTable(String, Type)

Returns the metadata that describes the specified table.


Returns the metadata that describes the specified table.


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Registers a data context instance by using a data-model provider

System_CAPS_pubmethodRegisterContext(DataModelProvider, ContextConfiguration)

Registers a data-context instance by using the specified context configuration and by enabling a data-model provider.


Registers the data context that is specified by a context factory.

System_CAPS_pubmethodRegisterContext(Func<Object>, ContextConfiguration)

Registers a data-context instance by using the specified context configuration and by enabling a custom constructor.


Registers a data-context instance.

System_CAPS_pubmethodRegisterContext(Type, ContextConfiguration)

Registers a data-context instance by using the specified context configuration.


Resets any previous context registration error that might have occurred.


Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodTryGetTable(String, MetaTable)

Attempts to get the metadata that is associated with the specified table.

System_CAPS_pubmethodTryGetTable(Type, MetaTable)

Attempts to get the metadata that is associated with the specified table.

Exception Condition

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.

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)

    // Get the data model. 
    public MetaModel GetModel(bool defaultModel)
        MetaModel model;

        if (defaultModel)
            model = MetaModel.Default;
            model =
        return model;

    // Get the registered action path.
    public string EvaluateActionPath()
        string tableName = LinqDataSource1.TableName;

        MetaModel model = GetModel(false);

        string actionPath =
                System.Web.DynamicData.PageAction.List, GetDataItem());
        return actionPath;
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
Available since 3.5

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

Return to top