SQLServer数据库中的表对象 荣

基于http://www.cnblogs.com/admin11/archive/2007/09/01/878298.html 和 http://www.cnblogs.com/admin11/archive/2007/09/05/882898.html 中对数据库系统数据的读取,我们可以建立表对象。
我的表对象结构:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 数据库表信息类
/// </summary>
/// <author>天志</author>
/// <log date="2007-09-01">创建</log>
public class TableDT
{
    
public TableDT()
    {
        
//
        
// TODO: 在此处添加构造函数逻辑
        
//
    }

    
public TableDT(DataRowView dv)
    {
        
this._tableName = Convert.ToString(dv["tableName"]);
        
this._id = Convert.ToInt32(dv["id"]);
        
this._tableType = Convert.ToString(dv["tableType"]);
        
this._script = Convert.ToString(dv["script"]);
        
this._createDate = Convert.ToString(dv["createDate"]);
    }

    
/// <summary>
    
/// 数据库表名称
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    private string _tableName;

    
/// <summary>
    
/// 数据库表ID
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    private int _id;

    
/// <summary>
    
/// 数据库表类型
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    private string _tableType;

    
/// <summary>
    
/// 数据库表描述
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    private string _script;

    
/// <summary>
    
/// 数据库表创建日期
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    private string _createDate;

    
/// <summary>
    
/// 数据库表名
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    public string TableName
    {
        
set
        {
            
this._tableName = value;
        }
        
get
        {
            
return this._tableName;
        }
    }

    
/// <summary>
    
/// 数据库表ID
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    public int Id
    {
        
set
        {
            
this._id = value;
        }
        
get
        {
            
return this._id;
        }
    }

    
/// <summary>
    
/// 数据库表类型
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    public string TableType
    {
        
set
        {
            
this._tableType = value;
        }
        
get
        {
            
return this._tableType;
        }
    }

    
/// <summary>
    
/// 数据库表描述
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    public string Script
    {
        
set
        {
            
this._script = value;
        }
        
get
        {
            
return this._script;
        }
    }

    
/// <summary>
    
/// 数据库表创建日期
    
/// </summary>
    
/// <author>天志</author>
    
/// <log date="2007-09-01">创建</log>
    public string CreateDate
    {
        
set
        {
            
this._createDate = value;
        }
        
get
        {
            
return this._createDate;
        }
    }


}

这个对象里面收集了一个表的数据库表名称、数据库表ID、数据库表类型、数据库表描述、数据库表创建日期等信息。

我们可以建立一个泛型集合来存储表对象。

using System;
using System.Collections.Generic;

/// <summary>
/// 存储数据库表信息的集合
/// </summary>
/// <author>天志</author>
/// <log date="2007-09-01">创建</log>
public class TableList<T> : List<T> where T : TableDT
{
    
public TableList() : base()
    {
    }

    
public TableList(IEnumerable<T> collection)
        : 
base(collection)
    {
    }

    
public TableList(int capacity)
        : 
base(capacity)
    {
    }
}


表对象的结构要比列结构要简单,但是我们可以对表对象进行扩展。扩展的信息可以包括:表包含的列信息、当前表的主键信息,当前表的外键信息,当前表被哪些表当成外键表,当前表的标识字段是哪个,当前表的主键字段都有哪一些。
原文地址:https://www.cnblogs.com/admin11/p/896864.html