Recently study C #, found that writing code is very troublesome, especially to create entities, models, interfaces, factories, stored procedures and so on, some open-source online, but incomplete, can not be complete on demand generation, so, spent three days, combined with some of the experience of predecessors, integration of some code generator, the following is the method of generating stored procedures , you can use for reference, the level is limited, please give more advice.
1 /// <summary>2 ///create a stored procedure3 /// </summary> 4 Public stringgetstorage (codetable codetable)5 {6 7Model.servers Server =Common.Config.GetServer (Codetable.serverid);8 if(Server = =NULL)9 {Ten return string. Empty; One } AStringBuilder storage =NewStringBuilder (import. Getimport_storage ()); - - stringDbName =Codetable.dbname; the stringTableName =Codetable.tablename; -DataSet DataSet =idata. RunQuery (Codetable.serverid, DbName, tableName); -datarow[] rows = dataset.tables[0]. Select ("table_name = '"+ TableName +"'"); - + foreach(DataRow Drinchrows) - { + stringPrefix ="Lls_"; AStorage. Append (Createselectall (Prefix + tableName +"_selectall", TableName, rows) +"\r\n\r\n"); atStorage. Append (Createselectrow (Prefix + tableName +"_selectrow", TableName, rows) +"\r\n\r\n"); -Storage. Append (Createinsert (Prefix + tableName +"_insert", TableName, rows) +"\r\n\r\n"); -Storage. Append (createupdate (Prefix + tableName +"_update", TableName, rows) +"\r\n\r\n"); -Storage. Append (Createdeleterow (Prefix + tableName +"_deleterow", TableName, rows) +"\r\n\r\n"); - Break; - } in returnstorage. ToString (); -}
C # code generator (stored procedure generation method)