MetaModel.Tables Property
.NET Framework (current version)
Gets a collection of all the tables that are part of the data model.
Assembly: System.Web.DynamicData (in System.Web.DynamicData.dll)
The collection contains all the tables in the data model, which includes the tables that are not visible (are not part of Dynamic Data scaffolding).
Run an online example of this feature.
The following example shows how to use the Tables and VisibleTables properties to perform the following tasks:
Get a collection of all the tables in a data model and show them in a GridView control.
Get a collection of the visible tables in a data model and show them in a GridView control.
The example consists of a page and its code-behind file.
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="TablesMenu.aspx.vb" Inherits="_TablesMenu" %> <!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>Tables</h2> <form id="Form1" runat="server"> <h4>Visible Tables</h4> <asp:GridView ID="Menu1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Table Name" SortExpression="TableName"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("ListActionPath") %>'><%#Eval("DisplayName") %></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <h4>Tables in the Data Model</h4> <asp:GridView ID="Menu2" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Table Name" SortExpression="TableName"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("ListActionPath") %>'><%#Eval("DisplayName") %></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body>
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 Imports System.Text Partial Public Class _TablesMenu Inherits System.Web.UI.Page 'Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) ' GetVisibleTables() ' GetTables() 'End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 'Dim visibleTables As System.Collections.IList = MetaModel.Default.VisibleTables 'If (visibleTables.Count = 0) Then ' Throw New InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax a" & _ ' "nd scaffolding is enabled or implement custom pages.") 'End If 'Menu1.DataSource = visibleTables 'Menu1.DataBind() GetVisibleTables() GetTables() End Sub ' Gets all the tables in the data model. Protected Sub GetTables() Dim tables As System.Collections.IList = MetaModel.[Default].Tables If tables.Count = 0 Then Throw New InvalidOperationException("There are no tables in the data model.") End If Menu2.DataSource = tables Menu2.DataBind() End Sub ' Gets only the visible tables in the data model. Protected Sub GetVisibleTables() Dim visibleTables As System.Collections.IList = MetaModel.[Default].VisibleTables If visibleTables.Count = 0 Then Throw New InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.") End If Menu1.DataSource = visibleTables Menu1.DataBind() End Sub End Class
.NET Framework
Available since 3.5
Available since 3.5
Show: