Partage via


MetaModel.GetTable Méthode

Définition

Retourne les métadonnées qui décrivent une table de modèles de données.

Surcharges

GetTable(String, Type)

Retourne les métadonnées qui décrivent la table spécifiée.

GetTable(Type)

Retourne les métadonnées qui décrivent la table spécifiée.

GetTable(String)

Retourne les métadonnées associées à la table spécifiée.

Exemples

L’exemple suivant montre comment utiliser les GetTable méthodes surchargées pour effectuer les tâches suivantes :

  • Obtenez l’objet MetaTable pour la table spécifiée.

  • Accédez aux informations de métadonnées contenues par l’objet MetaTable .

L’exemple se compose d’une page et de son fichier code-behind.

<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="GetTable.aspx.cs" 
Inherits="DocGetTable" %>

<!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></title>
</head>
<body>
    <h2>GetTable Methods</h2>

    <form runat="server">
  
     <asp:GridView ID="GridDataSource1" runat="server"
        AutoGenerateColumns="false"
        DataSourceID="LinqDataSource1"
        AllowPaging="true">
        <Columns>
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />
          <asp:TemplateField HeaderText="Addresses">
            <ItemTemplate>
              <%# GetAdresses(2)%>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
        
    </form>
    
     <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext" >
      </asp:LinqDataSource>
</body>
<%@ Page Language="VB" AutoEventWireup="false" 
CodeFile="GetTable.aspx.vb" 
Inherits="GetTable" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title></title>
</head>
<body>
    <h2>GetTable Methods</h2>

    <form id="Form1" runat="server">
  
     <asp:GridView ID="GridDataSource1" runat="server"
        AutoGenerateColumns="false"
        DataSourceID="LinqDataSource1"
        AllowPaging="true">
        <Columns>
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />
          <asp:TemplateField HeaderText="Addresses">
            <ItemTemplate>
              <%# GetAdresses(2)%>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
        
    </form>
    
     <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext" >
      </asp:LinqDataSource>
</body>
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;
using System.Text;

public partial class DocGetTable : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e) 
     {
     }

    // Use GetTable methods.
    public string GetAdresses(int index)
    {
        // Get the default data model.
        MetaModel model = MetaModel.Default;
   
        MetaTable mTable;

        switch (index)
        {
            case 0:
                // Get the metatable for the table with the
                // specified entity type.
                mTable = model.GetTable(typeof(CustomerAddress));
                break;
            case 1:
                // Get the metatable for the table with the 
                // specified table name.
                mTable = model.GetTable("CustomerAddresses");
                break;
            case 2:
                // Get the metatable for the table with the 
                // specified table name and the specified data
                // context.
                mTable = model.GetTable("CustomerAddresses", typeof(AdventureWorksLTDataContext));
                break;
            default:
                mTable = model.GetTable(typeof(CustomerAddress));
                break;
        }

        // The following code dislays the actual value 
        // (adress) associated with a customer and link
        // to the related Addresses table.
        MetaForeignKeyColumn fkColumn = 
            (MetaForeignKeyColumn)mTable.GetColumn("Address");

        Customer row = (Customer)GetDataItem();

        StringBuilder addressList = new StringBuilder();

        foreach (CustomerAddress childRow in row.CustomerAddresses)
        {
            addressList.Append(childRow.AddressType);
            addressList.Append(":<br/>");
            addressList.Append("<a href='");
            addressList.Append(fkColumn.GetForeignKeyDetailsPath(childRow.Address));
            addressList.Append("'>");
            addressList.Append(childRow.Address.AddressLine1);
            addressList.Append("</a><br/><br/>");
        }

        return addressList.ToString();
    }
}
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
Imports System.Text

Partial Public Class DocGetTable
    Inherits System.Web.UI.Page
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

     End Sub

    ' Use GetTable methods.
    Public Function GetAdresses(ByVal index As Integer) As String
        ' Get the default data model.
        Dim model As MetaModel = MetaModel.Default

        Dim mTable As MetaTable

        Select Case index
            Case 0
                ' Get the metatable for the table with the
                ' specified entity type.
                mTable = model.GetTable(GetType(CustomerAddress))
            Case 1
                ' Get the metatable for the table with the 
                ' specified table name.
                mTable = model.GetTable("CustomerAddresses")
            Case 2
                ' Get the metatable for the table with the 
                ' specified table name and the specified data
                ' context.
                mTable = model.GetTable("CustomerAddresses", GetType(AdventureWorksLTDataContext))
            Case Else
                mTable = model.GetTable(GetType(CustomerAddress))
        End Select

        ' The following code dislays the actual value 
        ' (adress) associated with a customer and link
        ' to the related Addresses table.
        Dim fkColumn As MetaForeignKeyColumn = CType(mTable.GetColumn("Address"), MetaForeignKeyColumn)

        Dim row As Customer = CType(GetDataItem(), Customer)


        Dim addressList As New StringBuilder()

        For Each childRow As CustomerAddress In row.CustomerAddresses
            addressList.Append(childRow.AddressType)
            addressList.Append(":<br/>")
            addressList.Append("<a href='")
            addressList.Append(fkColumn.GetForeignKeyDetailsPath(childRow.Address))
            addressList.Append("'>")
            addressList.Append(childRow.Address.AddressLine1)
            addressList.Append("</a><br/><br/>")
        Next childRow

        Return addressList.ToString()

    End Function

End Class

Remarques

L’objet MetaTable retourné par les méthodes surchargées contient les informations de métadonnées associées à la table spécifiée.

Exécutez un exemple en ligne de cette fonctionnalité.

GetTable(String, Type)

Retourne les métadonnées qui décrivent la table spécifiée.

public:
 System::Web::DynamicData::MetaTable ^ GetTable(System::String ^ tableName, Type ^ contextType);
public System.Web.DynamicData.MetaTable GetTable (string tableName, Type contextType);
member this.GetTable : string * Type -> System.Web.DynamicData.MetaTable
Public Function GetTable (tableName As String, contextType As Type) As MetaTable

Paramètres

tableName
String

Nom de la table.

contextType
Type

Contexte de données à rechercher pour la table.

Retours

MetaTable

Métadonnées qui décrivent la table spécifiée.

Exceptions

tablename ou contextType est null.

Le contexte n'est pas enregistré ou la table n'existe pas dans le contexte de données.

Exemples

L’exemple suivant montre comment utiliser la GetTable(String, Type) méthode pour obtenir les métadonnées de la table spécifiée. Pour obtenir un exemple complet, consultez GetTable.

// Get the metatable for the table with the 
// specified table name and the specified data
// context.
mTable = model.GetTable("CustomerAddresses", typeof(AdventureWorksLTDataContext));
' Get the metatable for the table with the 
' specified table name and the specified data
' context.
mTable = model.GetTable("CustomerAddresses", GetType(AdventureWorksLTDataContext))

Voir aussi

S’applique à

GetTable(Type)

Retourne les métadonnées qui décrivent la table spécifiée.

public:
 System::Web::DynamicData::MetaTable ^ GetTable(Type ^ entityType);
public System.Web.DynamicData.MetaTable GetTable (Type entityType);
member this.GetTable : Type -> System.Web.DynamicData.MetaTable
Public Function GetTable (entityType As Type) As MetaTable

Paramètres

entityType
Type

Type qui identifie la table dans le modèle de données.

Retours

MetaTable

Métadonnées qui décrivent la table spécifiée.

Exceptions

Type introuvable dans le modèle de données.

Exemples

L’exemple suivant montre comment utiliser la GetTable(Type) méthode pour obtenir les métadonnées de la table spécifiée. Pour obtenir un exemple complet, consultez GetTable.

// Get the metatable for the table with the
// specified entity type.
mTable = model.GetTable(typeof(CustomerAddress));
' Get the metatable for the table with the
' specified entity type.
mTable = model.GetTable(GetType(CustomerAddress))

Voir aussi

S’applique à

GetTable(String)

Retourne les métadonnées associées à la table spécifiée.

public:
 System::Web::DynamicData::MetaTable ^ GetTable(System::String ^ uniqueTableName);
public System.Web.DynamicData.MetaTable GetTable (string uniqueTableName);
member this.GetTable : string -> System.Web.DynamicData.MetaTable
Public Function GetTable (uniqueTableName As String) As MetaTable

Paramètres

uniqueTableName
String

Nom qui identifie la table dans le modèle de données.

Retours

MetaTable

Métadonnées qui décrivent la table spécifiée.

Exceptions

Nom introuvable dans le modèle de données.

Exemples

L’exemple suivant montre comment utiliser la GetTable(String) méthode pour obtenir les métadonnées de la table spécifiée. Pour obtenir un exemple complet, consultez GetTable.

// Get the metatable for the table with the 
// specified table name.
mTable = model.GetTable("CustomerAddresses");
' Get the metatable for the table with the 
' specified table name.
mTable = model.GetTable("CustomerAddresses")

Remarques

Le nom identifie de manière unique une table dans le modèle de données et est utilisé pour générer l’URL associée pour le routage.

Voir aussi

S’applique à