• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
.NET 技术
我要飞得更高
博客园    首页    新随笔    联系   管理    订阅  订阅

根据数据库列自动生成代码 CodeDom

写了个利用CodeDom根据数据库的行生成.net对象文件的DLL,
https://files.cnblogs.com/pwrjng/代码自动生成Demo.rar
代码的自动生成

以Northwind为例,ConnectionString = 你自己的COnnectionString
DataBaseName = 你的Database的名字,比如Northwind,AdventureWork
TableName = 你的表的名字,比如Customers

MyLibrary.MyCodeDom code = new MyLibrary.MyCodeDom(ConnectionString,DataBaseName,TableName);
code.GenerateCSharpCode(Server.MapPath("Test2.cs"));

生成的文件的Demo, 因为是Demo只提供到field,Property类。应该还是有function的,比较懒还没写道,哈~
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Northwind.Customers
{
    using System;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
   
   
    public class Customers
    {
       
        private string _CustomerID;
       
        private string _CompanyName;
       
        private string _ContactName;
       
        private string _ContactTitle;
       
        private string _Address;
       
        private string _City;
       
        private string _Region;
       
        private string _PostalCode;
       
        private string _Country;
       
        private string _Phone;
       
        private string _Fax;
       
        public virtual string CustomerID
        {
            get
            {
                return this._CustomerID;
            }
            set
            {
                this._CustomerID = value;
            }
        }
       
        public virtual string CompanyName
        {
            get
            {
                return this._CompanyName;
            }
            set
            {
                this._CompanyName = value;
            }
        }
       
        public virtual string ContactName
        {
            get
            {
                return this._ContactName;
            }
            set
            {
                this._ContactName = value;
            }
        }
       
        public virtual string ContactTitle
        {
            get
            {
                return this._ContactTitle;
            }
            set
            {
                this._ContactTitle = value;
            }
        }
       
        public virtual string Address
        {
            get
            {
                return this._Address;
            }
            set
            {
                this._Address = value;
            }
        }
       
        public virtual string City
        {
            get
            {
                return this._City;
            }
            set
            {
                this._City = value;
            }
        }
       
        public virtual string Region
        {
            get
            {
                return this._Region;
            }
            set
            {
                this._Region = value;
            }
        }
       
        public virtual string PostalCode
        {
            get
            {
                return this._PostalCode;
            }
            set
            {
                this._PostalCode = value;
            }
        }
       
        public virtual string Country
        {
            get
            {
                return this._Country;
            }
            set
            {
                this._Country = value;
            }
        }
       
        public virtual string Phone
        {
            get
            {
                return this._Phone;
            }
            set
            {
                this._Phone = value;
            }
        }
       
        public virtual string Fax
        {
            get
            {
                return this._Fax;
            }
            set
            {
                this._Fax = value;
            }
        }
    }
}

posted on 2006-12-08 13:02  pwrjng  阅读(451)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3