2024年1月26日发(作者:)

public string RazorParse(string tablename, string tablecomment){StringBuilder builder = new StringBuilder();var columsInfo = ry<ColumnInfo>((@"selecttable_name,column_name,ordinal_position,is_nullable,data_type,character_maximum_length,column_key,column_commentfrom information_Swhere table_schema = '{0}' and table_name = '{1}'", dbschema, tablename)).ToList();foreach (var item in columsInfo){_type = ype(_type);if (!_("string") && _("YES")){_type = _type + "?";}}#region entityvar entity_result = (entity_template, new{EntityNameSpace = "",EntityName = tablename,Columns = columsInfo},"entity");(e(ationBase, "CodeGenerateCodeEntity", $"{tablename}.cs"), entity_result);(entity_result);#endregion#region dtovar dto_result = (dto_template, new{DtoNameSpace = "",DtoName = lName(tablename) + "Info",Columns = columsInfo},"dto");(e(ationBase, "CodeGenerateCodeDto", $"{lName(tablename) + "Info"}.cs"), dto_result);(dto_result);#endregion

#region appvar app_result = (app_template, new{AppNameSpace = "ents",DtoName = lName(tablename) + "Info",AppClassName = lName(tablename),Table = tablename,Columns = columsInfo},"app");(e(ationBase, "CodeGenerateCodeApplication", $"{lName(tablename) + "Service"}.cs"), app_result);(app_result);#endregion#region controllervar ctrl_result = (ctrl_template, new{AppClassName = lName(tablename),DtoName = lName(tablename) + "Info",TableComment = tablecomment,},"ctrl");(e(ationBase, "CodeGenerateCodeController", $"{lName(tablename) + "Controller"}.cs"), ctrl_result);(ctrl_result);#endregionreturn ng();}public class ColumnInfo{public string table_name { get; set; }public string column_name { get; set; }public int? ordinal_position { get; set; }public string is_nullable { get; set; }public string data_type { get; set; }public int? character_maximum_length { get; set; }public string column_key { get; set; }public string column_comment { get; set; }}public class TableInfo{public string table_name { get; set; }public string table_comment { get; set; }}}}-----------------------------------

-----------------------------------using ;using ;namespace ConsoleApp1{public class Utils{/// <summary>/// 类型转化/// </summary>/// <param name="dbType"></param>/// <returns></returns>public static string GetCsType(string dbType){string csType = "";switch (r()){case "varchar":case "varchar2":case "nvarchar":case "nvarchar2":case "char":case "nchar":case "text":case "longtext":case "string":csType = "string";break;case "date":case "datetime":case "smalldatetime":case "timestamp":csType = "DateTime";break;case "int":case "number":case "smallint":case "integer":csType = "int";break;case "bigint":csType = "Int64";break;

case "float":case "numeric":case "decimal":case "money":case "smallmoney":case "real":case "double":csType = "decimal";break;case "tinyint":case "bit":csType = "bool";break;case "binary":case "varbinary":case "image":case "raw":case "long":case "long raw":case "blob":case "bfile":csType = "byte[]";break;case "uniqueidentifier":csType = "Guid";break;case "xml":case "json":csType = "string";break;default:csType = "object";break;}return csType;}/// <summary>/// 保存/// </summary>/// <param name="path"></param>/// <param name="content"></param>/// <returns></returns>public static string Save(string path, string content){string dir = ing(0, dexOf("") + 1);if (!(dir)) Directory(dir);llText(path, content);return path;}private static regSpace = new (@"s");