The code for the T4 template below will give you a relatively good start.
You will need to add references to the appropriate versions of the Microsoft.SqlSserver Smo DLLs to the project.
The following items need to be replaced in this code with the appropriate values for your environment:
SERVERNAMEGOESHERE
DATABASENAMEGOESHERE
PROJECTNAMESPACEGOESHERE
<#@ template language="C#v3.5" hostspecific="true" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="Microsoft.SqlServer.Management.Common" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#
string connectionString = @"Server=SERVERNAMEGOESHERE;Trusted_Connection=True;";
string databaseName = "DATABASENAMEGOESHERE";
string projectNamespace = "PROJECTNAMESPACEGOESHERE";
string relativeOutputFilePath = null;
SqlConnection oneSqlConnection = new SqlConnection(connectionString);
ServerConnection oneServerConnection = new ServerConnection(oneSqlConnection);
Server oneServer = new Server(oneServerConnection);
Database oneDatabase = oneServer.Databases[databaseName];
foreach (Table oneTable in oneDatabase.Tables)
{
if (!oneTable.Name.Equals("sysdiagrams"))
{
#>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="<#= oneTable.Name #>_List.aspx.cs" Inherits="<#= projectNamespace #>.<#= oneTable.Name #>_List" %>
<asp:DataGrid ID="<#= oneTable.Name #>DataGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<#
foreach (Column oneColumn in oneTable.Columns)
{
#>
<asp:BoundColumn DataField="<#= oneColumn.Name #>" HeaderText="<#= oneColumn.Name #>"></asp:BoundColumn>
<#
}
#>
</Columns>
</asp:DataGrid>
<#
relativeOutputFilePath = @"\Output\" + oneTable.Name + "_List.aspx";
TemplateHelper.WriteTemplateOutputToFile(relativeOutputFilePath, Host, GenerationEnvironment);
GenerationEnvironment = new System.Text.StringBuilder();
#>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="<#= oneTable.Name #>_Edit.aspx.cs" Inherits="<#= projectNamespace #>.<#= oneTable.Name #>_Edit" %>
<#
foreach (Column oneColumn in oneTable.Columns)
{
#>
<asp:TextBox ID="<#= oneColumn.Name #>TextBox" runat="server" />
<#
}
relativeOutputFilePath = @"\Output\" + oneTable.Name + "_Edit.aspx";
TemplateHelper.WriteTemplateOutputToFile(relativeOutputFilePath, Host, GenerationEnvironment);
GenerationEnvironment = new System.Text.StringBuilder();
}
}
#>
<#+
public class TemplateHelper
{
public static void WriteTemplateOutputToFile(
string relativeOutputFilePath,
Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost Host,
System.Text.StringBuilder GenerationEnvironment)
{
string outputPath = System.IO.Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = outputPath + relativeOutputFilePath;
System.IO.File.WriteAllText(outputFilePath, GenerationEnvironment.ToString());
}
}
#>