MetaModel MetaModel MetaModel MetaModel Class

定義

表示 ASP.NET Dynamic Data 所使用的一個或多個資料庫。Represents one or multiple databases that are used by ASP.NET Dynamic Data.

public ref class MetaModel
public class MetaModel
type MetaModel = class
Public Class MetaModel
繼承
MetaModelMetaModelMetaModelMetaModel

範例

下列範例示範如何使用MetaModel型別,若要使用自動 scaffolding ASP.NET 網站中執行下列工作: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.

  • 評估與路由的路徑 (判斷的 URL) 指定的資料表。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.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

[MetadataType(typeof(ProductMetaData))]
public partial class Product
{

}


public class ProductMetaData
{
    
 

}
 
<%@ 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 xmlns="http://www.w3.org/1999/xhtml">
<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>

<%@ 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 xmlns="http://www.w3.org/1999/xhtml">
<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

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;
    }
}
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

若要編譯此範例,您需要下列項目:To compile the example, you need the following:

請參閱這項功能的執行階段程式碼範例:執行See a run-time code example of this feature: Run.

備註

MetaModel類型可讓您註冊為 Dynamic Data Web 應用程式的一或多個資料內容。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. 物件,表示當做 CLR 類型的資料庫的資料實體資料模型。A data model is an object that represents a database's data entities as CLR types. 動態資料支援根據 LINQ to SQL 和 ADO.NET Entity Framework 的資料模型。Dynamic Data supports data models based on LINQ to SQL and on the ADO.NET Entity Framework.

在 Visual Studio 中,您可以產生資料模型類型使用LINQ to SQL 類別範本或有ADO.NET 實體資料模型範本。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. 這些範本會使用物件關聯式設計工具 (O/R 設計工具),LINQ to SQL 模型或 ADO.NET 實體資料模型設計工具 (Entity Designer) Entity Framework 模型。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.

建構函式

MetaModel() MetaModel() MetaModel() MetaModel()

執行個體化 MetaModel 類別的新執行個體。Instantiates a new instance of the MetaModel class.

MetaModel(Boolean) MetaModel(Boolean) MetaModel(Boolean) MetaModel(Boolean)

執行個體化 MetaModel 類別的新執行個體。Instantiates a new instance of the MetaModel class.

屬性

Default Default Default Default

取得應用程式所建立的第一個資料模型執行個體。Gets the first instance of a data model that is created by the application.

DynamicDataFolderVirtualPath DynamicDataFolderVirtualPath DynamicDataFolderVirtualPath DynamicDataFolderVirtualPath

取得或設定網站中 [DynamicData] 資料夾的虛擬路徑。Gets or sets the virtual path of the DynamicData folder in the Web site.

EntityTemplateFactory EntityTemplateFactory EntityTemplateFactory EntityTemplateFactory

取得或設定與模型相關聯的 EntityTemplateFactory 物件。Gets or sets the EntityTemplateFactory object that is associated with the model.

FieldTemplateFactory FieldTemplateFactory FieldTemplateFactory FieldTemplateFactory

取得或設定自訂 IFieldTemplateFactory 介面。Gets or sets a custom IFieldTemplateFactory interface.

FilterFactory FilterFactory FilterFactory FilterFactory

取得或設定與模型相關聯的 FilterFactory 物件。Gets or sets the FilterFactory object that is associated with the model.

Tables Tables Tables Tables

取得屬於資料模型之所有資料表的集合。Gets a collection of all the tables that are part of the data model.

VisibleTables VisibleTables VisibleTables VisibleTables

取得資料模型中可見資料表的集合。Gets a collection of the visible tables in the data model.

方法

CreateTable(TableProvider) CreateTable(TableProvider) CreateTable(TableProvider) CreateTable(TableProvider)

執行個體化 MetaTable 物件。Instantiates a MetaTable object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetActionPath(String, String, Object) GetActionPath(String, String, Object) GetActionPath(String, String, Object) GetActionPath(String, String, Object)

傳回與特定資料表相關聯的動作路徑。Returns the action path that is associated with a specific table.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetModel(Type) GetModel(Type) GetModel(Type) GetModel(Type)

傳回指定之內容的資料模型執行個體。Returns the data-model instance for the specified context.

GetTable(String) GetTable(String) GetTable(String) GetTable(String)

傳回與指定之資料表相關聯的中繼資料。Returns the metadata that is associated with the specified table.

GetTable(String, Type) GetTable(String, Type) GetTable(String, Type) GetTable(String, Type)

傳回描述指定之資料表的中繼資料。Returns the metadata that describes the specified table.

GetTable(Type) GetTable(Type) GetTable(Type) GetTable(Type)

傳回描述指定之資料表的中繼資料。Returns the metadata that describes the specified table.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
RegisterContext(DataModelProvider) RegisterContext(DataModelProvider) RegisterContext(DataModelProvider) RegisterContext(DataModelProvider)

使用資料模型提供者,註冊資料內容執行個體。Registers a data context instance by using a data-model provider

RegisterContext(DataModelProvider, ContextConfiguration) RegisterContext(DataModelProvider, ContextConfiguration) RegisterContext(DataModelProvider, ContextConfiguration) RegisterContext(DataModelProvider, ContextConfiguration)

使用指定的內容組態並啟用資料模型提供者 (Provider),註冊資料內容執行個體。Registers a data-context instance by using the specified context configuration and by enabling a data-model provider.

RegisterContext(Func<Object>) RegisterContext(Func<Object>) RegisterContext(Func<Object>) RegisterContext(Func<Object>)

註冊內容 Factory 所指定的資料內容。Registers the data context that is specified by a context factory.

RegisterContext(Func<Object>, ContextConfiguration) RegisterContext(Func<Object>, ContextConfiguration) RegisterContext(Func<Object>, ContextConfiguration) RegisterContext(Func<Object>, ContextConfiguration)

使用指定的內容組態並啟用自訂建構函式,註冊資料內容執行個體。Registers a data-context instance by using the specified context configuration and by enabling a custom constructor.

RegisterContext(Type) RegisterContext(Type) RegisterContext(Type) RegisterContext(Type)

註冊資料內容執行個體。Registers a data-context instance.

RegisterContext(Type, ContextConfiguration) RegisterContext(Type, ContextConfiguration) RegisterContext(Type, ContextConfiguration) RegisterContext(Type, ContextConfiguration)

使用指定的內容組態,註冊資料內容執行個體。Registers a data-context instance by using the specified context configuration.

ResetRegistrationException() ResetRegistrationException() ResetRegistrationException() ResetRegistrationException()

重設任何可能已發生的先前內容註冊錯誤。Resets any previous context registration error that might have occurred.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TryGetTable(String, MetaTable) TryGetTable(String, MetaTable) TryGetTable(String, MetaTable) TryGetTable(String, MetaTable)

嘗試取得與指定之資料表相關聯的中繼資料。Attempts to get the metadata that is associated with the specified table.

TryGetTable(Type, MetaTable) TryGetTable(Type, MetaTable) TryGetTable(Type, MetaTable) TryGetTable(Type, MetaTable)

嘗試取得與指定之資料表相關聯的中繼資料。Attempts to get the metadata that is associated with the specified table.

適用於

另請參閱