快速生成数据库列枚举的小技巧
需要对数据库的列生成枚举比如 Dict 表结构是:
要生成的枚举是:
可在 SQL 2008 里快速生成:
SQL2008 给开发者提供的最大好处是 列出成员 了, 快捷键和 VS 一样. (Ctrl+J) . 超爽.
CREATE TABLE [dbo].[Dict](
[ID] [int] IDENTITY(1,1) NOT NULL,
[PID] [int] NULL,
[Key] [varchar](50) NULL,
[Value] [varchar](128) NULL,
[SortID] [int] NOT NULL,
CONSTRAINT [PK_Dict] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
[ID] [int] IDENTITY(1,1) NOT NULL,
[PID] [int] NULL,
[Key] [varchar](50) NULL,
[Value] [varchar](128) NULL,
[SortID] [int] NOT NULL,
CONSTRAINT [PK_Dict] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
要生成的枚举是:
public enum MasterIndex
{
Select ,
Edit ,
ID,
PID,
Key,
Value,
SortID,
Del,
}
{
Select ,
Edit ,
ID,
PID,
Key,
Value,
SortID,
Del,
}
可在 SQL 2008 里快速生成:
select name + ',' from .sys.all_columns where .sys.all_columns.object_id = object_id('[Dict]' )
SQL2008 给开发者提供的最大好处是 列出成员 了, 快捷键和 VS 一样. (Ctrl+J) . 超爽.
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |