根据数据库列自动生成代码 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;
}
}
}
}
浙公网安备 33010602011771号