生成简单实体的sql

select 'namespace CE.EIP.DataEntity'
union all
select '{'
union all
select '      using System;'
union all
select '      using Castle.ActiveRecord;'
union all
select '      using CE.EIP.Base;'
union all
select ''
union all
select '      [ActiveRecord("TAdmin")]'
union all
select '      public class AdminEntity : BaseEntity'
union all
select '      {'
union all
select '          private '+case systypes.name when 'varchar' then 'string' when 'datetime' then 'DateTime' else systypes.name end+' _'
+syscolumns.name +';'
FROM syscolumns INNER JOIN
        sysobjects ON syscolumns.id = sysobjects.id INNER JOIN
        systypes ON syscolumns.xtype = systypes.xtype
WHERE (sysobjects.name = N'Admin')
union all
select '          [Property()]'+char(13) +'          public '+case systypes.name when 'varchar' then 'string' when 'datetime' then 'DateTime' else systypes.name end+' '+ syscolumns.name    +char(13)
+'        {'+char(13)
+'              get'+char(13)
+'              {'+char(13)
+'                  return this._'+syscolumns.name+';'+char(13)
+'              }'+char(13)
+'              set'+char(13)
+'              {'+char(13)
+'                  this._'+syscolumns.name+' = value;'+char(13)
+'              }'+char(13)
+'          }'
FROM syscolumns INNER JOIN
        sysobjects ON syscolumns.id = sysobjects.id INNER JOIN
        systypes ON syscolumns.xtype = systypes.xtype
WHERE (sysobjects.name = N'Admin')
union all
select '      }'
union all
select '}'

你可能感兴趣的:(sql)