Previously wrote a C #, suffering from the compilation to use. Such gadgets are best written in scripting languages, easy to execute, and easy to modify.
JS Code convert.js
--------------------------------------------------
string.prototype.trim=function(){ return This. Replace (/(^\s*) | ( \s*$)/g, "");} String.prototype.ltrim=function(){ return This. Replace (/(^\s*)/g, "");} String.prototype.rtrim=function(){ return This. Replace (/(\s*$)/g, "");} String.prototype.startWith=function(str) {varReg =NewRegExp ("^" +str); returnReg.test ( This);}varConvertcode ={content:"", run:function() {Console.WriteLine ( This. Content); if( ! This. Content)return; varLines = This. content.split (' \ n '); varret = ""; for(vari=0; i<lines.length; i++) { varDatainfo = This. Convertline (Lines[i]); if(!datainfo)Continue; RET= ret + "///<summary>\n"; RET= ret + "///\n"; RET= ret + "///<summary>\n"; RET= ret + ' [DbColumn ("' + Datainfo.column + '")]\n '; RET= ret + "public" + Datainfo.datatype + "" + Datainfo.name + "{get;set;} \ n "; } returnret; }, Convertline:function(line) { line=Line.trim (); if(Line.length = = 0)return NULL; varTokens = Line.split (/\s+/); if(Tokens.length <= 1)return NULL; return{column:tokens[0], Name: This. Tonormalname (Tokens[0]), DataType: This. Todatatype (tokens[1]) }; }, Tonormalname:function(Raw) {vartokens = Raw.split (' _ ')); varret = ""; for(vari=0; i<tokens.length; i++) {ret= ret + TOKENS[I].SUBSTR (0,1). toUpperCase () + TOKENS[I].SUBSTR (1); } returnret; }, Todatatype:function(d) {if(!d)return NULL; if(D.startwith ("varchar") | | | d.startwith ("char"))return"String"; if(D.startwith ("int"))return"Int"; if(D.startwith ("number"))return"Decimal"; if(D.startwith ("date"))return"DateTime"; return NULL; }}
The HTML code is used to call it
----------------------------------
<HTML><Head> <MetaCharSet= ' GBK '/> <Scripttype= ' Text/javascript 'src= "Convert.js"></Script> <Scriptlanguage= "JavaScript"type= ' Text/javascript '> varDoparse= function(){ varParser=Convertcode; Parser.content=document.getElementById ('content'). Value; varresult=Parser.run (content); document.getElementById ('Divresult'). Value=result; Console.WriteLine (document.getElementById ('Divresult'). Value); } </Script></Head><Body> <Div><inputtype= "button"value= "Convert"onclick= "Javascript:doparse ();"style= "width:50px; height:30px;"/></Div> <Divstyle= "float:left; width:500px;"> <textareaID= ' content 'style= "width:500px; height:600px;"></textarea> </Div> <Divstyle= "float:left; width:500px; margin-left:30px;" > <textareaID= "Divresult"style= "width:500px; height:600px;"></textarea> </Div> </Body></HTML>
A JS code for converting SQL scripts into entity classes