会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
javawebsoa
CnBlogs
Home
New Post
Contact
Admin
SQL Server 根据表名创建实体类的字段和属性
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ============================================= -- Author: <shipeng.wang> -- Create date: <2009-09-11> -- Description: <根据表名创建实体类的字段和属性> -- ============================================= ALTER proc [dbo].[p_Wsp] @tablename varchar(50) as declare @sql varchar(8000) select @sql=isnull(@sql+char(9)+'private ','public class '+@tablename+char(13)+'{'+char(13)+char(9)+'private ')+ case when a.name in('image','uniqueidentifier','ntext','varchar','ntext','nchar','nvarchar','text','char') then 'string' when a.name in('tinyint','smallint','int','bigint') then 'int' when a.name in('datetime','smalldatetime') then 'DateTime' when a.name in('float','decimal','numeric','money','real','smallmoney') then 'decimal' when a.name ='bit' then 'bool' else a.name end+' '+lower('_'+b.name)+';'+char(13)+char(9)+'public '+ case when a.name in('image','uniqueidentifier','ntext','varchar','ntext','nchar','nvarchar','text','char') then 'string' when a.name in('tinyint','smallint','int') then 'int' when a.name='bigint' then 'long' when a.name in('datetime','smalldatetime') then 'DateTime' when a.name in('float','decimal','numeric','money','real','smallmoney') then 'decimal' when a.name ='bit' then 'bool' else a.name end +' '+b.name+char(13)+char(9)+'{'+char(13)+char(9)+char(9)+'get{return '+lower('_'+b.name)+';}'+ char(13)+char(9)+char(9)+'set{'+lower('_'+b.name)+'=value;}'+char(13)+char(9)+'}'+char(13) from syscolumns b, (select distinct name,xtype from systypes where status=0) a where a.xtype=b.xtype and b.id=object_id(@tablename) set @sql=@sql+'}' print @sql
posted @
2011-04-23 16:02
javawebsoa
Views(
330
) Comments(
0
)
Edit
收藏
举报
刷新页面
返回顶部
公告