MetaModel.GetTable Method

Definition

Returns the metadata that describes a data model table.

Overloads

GetTable(String, Type)

Returns the metadata that describes the specified table.

GetTable(Type)

Returns the metadata that describes the specified table.

GetTable(String)

Returns the metadata that is associated with the specified table.

Examples

The following example shows how to use the GetTable overloaded methods to perform the following tasks:

  • Get the MetaTable object for the specified table.

  • Access the metadata information that is contained by the MetaTable object.

The example consists of a page and its code-behind file.

<%@ 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>
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();
    }
}

Remarks

The MetaTable object that is returned by the overloaded methods contains the metadata information that is associated with the specified table.

Run an online example of this feature.

GetTable(String, Type)

Returns the metadata that describes the specified table.

public System.Web.DynamicData.MetaTable GetTable (string tableName, Type contextType);

Parameters

tableName
String

The name of the table.

contextType
Type

The data context to search for the table.

Returns

The metadata that describes the specified table.

Exceptions

tablename or contextType is null.

The context is not registered or the table does not exist in the data context.

Examples

The following example shows how to use the GetTable(String, Type) method to obtain the metadata for the specified table. For a complete example, see GetTable.

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

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

GetTable(Type)

Returns the metadata that describes the specified table.

public System.Web.DynamicData.MetaTable GetTable (Type entityType);

Parameters

entityType
Type

The type that identifies the table in the data model.

Returns

The metadata that describes the specified table.

Exceptions

The type was not found in the data model.

Examples

The following example shows how to use the GetTable(Type) method to obtain the metadata for the specified table. For a complete example, see GetTable.

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

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

GetTable(String)

Returns the metadata that is associated with the specified table.

public System.Web.DynamicData.MetaTable GetTable (string uniqueTableName);

Parameters

uniqueTableName
String

The name that identifies the table in the data model.

Returns

The metadata that describes the specified table.

Exceptions

The name was not found in the data model.

Examples

The following example shows how to use the GetTable(String) method to obtain the metadata for the specified table. For a complete example, see GetTable.

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

Remarks

The name uniquely identifies a table in the data model and is used to generate the related URL for routing.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1