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