逆水行船

别人的天堂,是我的异乡;无端的繁华,倍添我的惆怅

 

SQL-Server数据库中的表对象

基于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)
    {
    }
}


表对象的结构要比列结构要简单,但是我们可以对表对象进行扩展。扩展的信息可以包括:表包含的列信息、当前表的主键信息,当前表的外键信息,当前表被哪些表当成外键表,当前表的标识字段是哪个,当前表的主键字段都有哪一些。

posted on   荣-  阅读(842)  评论(1编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

统计

点击右上角即可分享
微信分享提示