Code
declare @InsertSql varchar(max),@UpdateSql varchar(max),@DeleteSql varchar(max),@SelectSql varchar(max),@SelectAllSql varchar(max)
declare @sql varchar(max)
declare @TableName sysname,@TableAlias varchar(100)
declare @ModelClassName varchar(100),@ModelVarName varchar(100)
declare @sCRLF char(2),@sTAB char(1)
declare @InsertFlag bit,@UpdateFlag bit,@DeleteFlag bit,@SelectFlag bit,@SelectAllFlag bit
declare @CommentAuthor varchar(100)
--the 4 flags is used to control which method is generated.
set @InsertFlag=1
set @UpdateFlag=1
set @DeleteFlag=1
set @SelectFlag=1
set @SelectAllFlag=1
--table name, is same as table name in database.
set @TableName='aa_xx'
--table alias, is used to add a name after method,like InsertAccount,UpdateAccount etc.
set @TableAlias='xx'
--comment info
set @CommentAuthor='Amy'
SET @sTAB = char(9)
SET @sCRLF = char(13) + char(10)
set @ModelClassName=@TableName+'Info'
set @ModelVarName=lower(substring(@TableAlias,1,1))+substring(@TableAlias,2,len(@TableAlias))+'Info'
set @InsertSql=''
set @UpdateSql=''
set @DeleteSql=''
set @SelectSql=''
set @SelectAllSql=''
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// Description: Insert a record to table '+@TableName+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <param name="'+@ModelVarName+'">A model of table '+@TableName+'</param>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'public void Insert'+@TableAlias+'('+@ModelClassName+' '+@ModelVarName+', IDataAccessSession session)'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'{'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Insert sp=new pr_'+@TableName+'_Insert(session);'+@sCRLF
set @InsertSql=@InsertSql+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// Description: Update a record to table '+@TableName+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <param name="'+@ModelVarName+'">A model of table '+@TableName+'</param>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'public void Update'+@TableAlias+'('+@ModelClassName+' '+@ModelVarName+', IDataAccessSession session)'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'{'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Update sp=new pr_'+@TableName+'_Update(session);'+@sCRLF
set @UpdateSql=@UpdateSql+@sCRLF
select
@InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.'+column_name+' = '+@ModelVarName+'.'+column_name+';'+@sCRLF,
@UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.'+column_name+' = '+@ModelVarName+'.'+column_name+';'+@sCRLF
from information_schema.columns
where table_name=@TableName
set @InsertSql=@InsertSql+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'}'
set @UpdateSql=@UpdateSql+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'}'
declare @Params varchar(max),@SetParams varchar(max),@CommentParams varchar(max)
set @Params=''
set @SetParams=''
set @CommentParams=''
select
@Params=@Params
+(case c.data_type when 'bigint' then 'Nullable<Int64>'
when 'int' then 'Nullable<Int32>'
when 'smallint' then 'Nullable<Int16>'
when 'tinyint' then 'Nullable<Byte>'
when 'smalldatetime' then 'Nullable<DateTime>'
when 'datetime' then 'Nullable<DateTime>'
else 'string' end)
+' '+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))+',',
@SetParams=@SetParams+@sTAB+@sTAB+@sTAB+'sp.Parameters.'
+c.column_name+' = '
+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))+';'+@sCRLF,
@CommentParams=@CommentParams+@sTAB+@sTAB+'/// <param name="'
+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))
+'"></param>'+@sCRLF
from information_schema.COLUMNS c
inner join information_schema.KEY_COLUMN_USAGE kcu
on c.table_name=kcu.table_name and c.column_name=kcu.column_name
where c.table_name=@TableName
--delete the last ','
set @Params=substring(@Params,1,len(@Params)-1)
set @CommentParams=@CommentParams+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// Description: Delete a record from table '+@TableName+' by primary key'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @DeleteSql=@DeleteSql+@CommentParams
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'public void Delete'+@TableAlias+'('+@Params+', IDataAccessSession session)'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'{'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Delete sp=new pr_'+@TableName+'_Delete(session);'+@sCRLF
set @DeleteSql=@DeleteSql+@sCRLF
set @DeleteSql=@DeleteSql+@SetParams+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'}'
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// Description: Select a record from table '+@TableName+' by primary key'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @SelectSql=@SelectSql+@CommentParams
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// <returns>A model of table '+@TableName+'</returns>'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'public '+@ModelClassName+' Get'+@TableAlias+'ByKey('+@Params+', IDataAccessSession session)'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'{'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Select sp=new pr_'+@TableName+'_Select(session);'+@sCRLF
set @SelectSql=@SelectSql+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.Cmd = "KEY";'+@sCRLF
set @SelectSql=@SelectSql+@SetParams+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteQuery();'+@sCRLF
set @SelectSql=@SelectSql+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+@ModelClassName+' '+@ModelVarName+' = null;'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'for (int i = 0; i < sp.QueryResults.Count;i++)'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'{'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+@sTAB+@ModelVarName+' = sp.QueryResults[i];'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'}'+@sCRLF
--set @SelectSql=@SelectSql+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'return '+@ModelVarName+';'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'return sp.QueryResults();'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'}'
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// Description: Select all records from table '+@TableName+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <returns>IList contains all records in table '+@TableName+'</returns>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'public IList<'+@ModelClassName+'> GetAll'+@TableAlias+'s(IDataAccessSession session)'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'{'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Select sp=new pr_'+@TableName+'_Select(session);'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.Cmd = "All";'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteQuery();'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'return sp.QueryResults;'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'}'
set @sql=''
if @InsertFlag=1 set @sql=@sql+@InsertSql+@sCRLF+@sCRLF
if @UpdateFlag=1 set @sql=@sql+@UpdateSql+@sCRLF+@sCRLF
if @DeleteFlag=1 set @sql=@sql+@DeleteSql+@sCRLF+@sCRLF
if @SelectFlag=1 set @sql=@sql+@SelectSql+@sCRLF+@sCRLF
if @SelectAllFlag=1 set @sql=@sql+@SelectAllSql+@sCRLF+@sCRLF
--print @InsertSql
--print @UpdateSql
--print @DeleteSql
print @sql
declare @InsertSql varchar(max),@UpdateSql varchar(max),@DeleteSql varchar(max),@SelectSql varchar(max),@SelectAllSql varchar(max)
declare @sql varchar(max)
declare @TableName sysname,@TableAlias varchar(100)
declare @ModelClassName varchar(100),@ModelVarName varchar(100)
declare @sCRLF char(2),@sTAB char(1)
declare @InsertFlag bit,@UpdateFlag bit,@DeleteFlag bit,@SelectFlag bit,@SelectAllFlag bit
declare @CommentAuthor varchar(100)
--the 4 flags is used to control which method is generated.
set @InsertFlag=1
set @UpdateFlag=1
set @DeleteFlag=1
set @SelectFlag=1
set @SelectAllFlag=1
--table name, is same as table name in database.
set @TableName='aa_xx'
--table alias, is used to add a name after method,like InsertAccount,UpdateAccount etc.
set @TableAlias='xx'
--comment info
set @CommentAuthor='Amy'
SET @sTAB = char(9)
SET @sCRLF = char(13) + char(10)
set @ModelClassName=@TableName+'Info'
set @ModelVarName=lower(substring(@TableAlias,1,1))+substring(@TableAlias,2,len(@TableAlias))+'Info'
set @InsertSql=''
set @UpdateSql=''
set @DeleteSql=''
set @SelectSql=''
set @SelectAllSql=''
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// Description: Insert a record to table '+@TableName+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <param name="'+@ModelVarName+'">A model of table '+@TableName+'</param>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'public void Insert'+@TableAlias+'('+@ModelClassName+' '+@ModelVarName+', IDataAccessSession session)'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'{'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Insert sp=new pr_'+@TableName+'_Insert(session);'+@sCRLF
set @InsertSql=@InsertSql+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// Description: Update a record to table '+@TableName+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <param name="'+@ModelVarName+'">A model of table '+@TableName+'</param>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'public void Update'+@TableAlias+'('+@ModelClassName+' '+@ModelVarName+', IDataAccessSession session)'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'{'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Update sp=new pr_'+@TableName+'_Update(session);'+@sCRLF
set @UpdateSql=@UpdateSql+@sCRLF
select
@InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.'+column_name+' = '+@ModelVarName+'.'+column_name+';'+@sCRLF,
@UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.'+column_name+' = '+@ModelVarName+'.'+column_name+';'+@sCRLF
from information_schema.columns
where table_name=@TableName
set @InsertSql=@InsertSql+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @InsertSql=@InsertSql+@sTAB+@sTAB+'}'
set @UpdateSql=@UpdateSql+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @UpdateSql=@UpdateSql+@sTAB+@sTAB+'}'
declare @Params varchar(max),@SetParams varchar(max),@CommentParams varchar(max)
set @Params=''
set @SetParams=''
set @CommentParams=''
select
@Params=@Params
+(case c.data_type when 'bigint' then 'Nullable<Int64>'
when 'int' then 'Nullable<Int32>'
when 'smallint' then 'Nullable<Int16>'
when 'tinyint' then 'Nullable<Byte>'
when 'smalldatetime' then 'Nullable<DateTime>'
when 'datetime' then 'Nullable<DateTime>'
else 'string' end)
+' '+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))+',',
@SetParams=@SetParams+@sTAB+@sTAB+@sTAB+'sp.Parameters.'
+c.column_name+' = '
+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))+';'+@sCRLF,
@CommentParams=@CommentParams+@sTAB+@sTAB+'/// <param name="'
+lower(substring(c.column_name,1,1))
+substring(c.column_name,2,len(c.column_name))
+'"></param>'+@sCRLF
from information_schema.COLUMNS c
inner join information_schema.KEY_COLUMN_USAGE kcu
on c.table_name=kcu.table_name and c.column_name=kcu.column_name
where c.table_name=@TableName
--delete the last ','
set @Params=substring(@Params,1,len(@Params)-1)
set @CommentParams=@CommentParams+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// Description: Delete a record from table '+@TableName+' by primary key'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @DeleteSql=@DeleteSql+@CommentParams
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'/// <returns>void</returns>'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'public void Delete'+@TableAlias+'('+@Params+', IDataAccessSession session)'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'{'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Delete sp=new pr_'+@TableName+'_Delete(session);'+@sCRLF
set @DeleteSql=@DeleteSql+@sCRLF
set @DeleteSql=@DeleteSql+@SetParams+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteNonQuery();'+@sCRLF
set @DeleteSql=@DeleteSql+@sTAB+@sTAB+'}'
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// Description: Select a record from table '+@TableName+' by primary key'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @SelectSql=@SelectSql+@CommentParams
set @SelectSql=@SelectSql+@sTAB+@sTAB+'/// <returns>A model of table '+@TableName+'</returns>'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'public '+@ModelClassName+' Get'+@TableAlias+'ByKey('+@Params+', IDataAccessSession session)'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'{'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Select sp=new pr_'+@TableName+'_Select(session);'+@sCRLF
set @SelectSql=@SelectSql+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.Cmd = "KEY";'+@sCRLF
set @SelectSql=@SelectSql+@SetParams+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteQuery();'+@sCRLF
set @SelectSql=@SelectSql+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+@ModelClassName+' '+@ModelVarName+' = null;'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'for (int i = 0; i < sp.QueryResults.Count;i++)'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'{'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+@sTAB+@ModelVarName+' = sp.QueryResults[i];'+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'}'+@sCRLF
--set @SelectSql=@SelectSql+@sCRLF
--set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'return '+@ModelVarName+';'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+@sTAB+'return sp.QueryResults();'+@sCRLF
set @SelectSql=@SelectSql+@sTAB+@sTAB+'}'
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <summary>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// Author: : '+@CommentAuthor+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// CreateDate : '+convert(varchar(100),getdate(),111)+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// Description: Select all records from table '+@TableName+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// </summary>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <param name="session">Database session</param>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'/// <returns>IList contains all records in table '+@TableName+'</returns>'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'public IList<'+@ModelClassName+'> GetAll'+@TableAlias+'s(IDataAccessSession session)'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'{'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'pr_'+@TableName+'_Select sp=new pr_'+@TableName+'_Select(session);'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'sp.Parameters.Cmd = "All";'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'sp.ExecuteQuery();'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+@sTAB+'return sp.QueryResults;'+@sCRLF
set @SelectAllSql=@SelectAllSql+@sTAB+@sTAB+'}'
set @sql=''
if @InsertFlag=1 set @sql=@sql+@InsertSql+@sCRLF+@sCRLF
if @UpdateFlag=1 set @sql=@sql+@UpdateSql+@sCRLF+@sCRLF
if @DeleteFlag=1 set @sql=@sql+@DeleteSql+@sCRLF+@sCRLF
if @SelectFlag=1 set @sql=@sql+@SelectSql+@sCRLF+@sCRLF
if @SelectAllFlag=1 set @sql=@sql+@SelectAllSql+@sCRLF+@sCRLF
--print @InsertSql
--print @UpdateSql
--print @DeleteSql
print @sql