c#根据数据表列生成实体类代码
StringBuilder sb = new StringBuilder();
sb.AppendLine("using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n ");
sb.AppendLine("namespace Model\n{");
sb.AppendLine($" public class {dt.TableName}");
sb.AppendLine(" {");
/*将sql类型转换成c#类型*/
foreach (DataColumn column in dt.Columns)
{
var colName = column.ColumnName;
var colType = column.DataType.Name;
//Console.WriteLine(colName + ":" + colType);
string propertyType = MapSqlTypeToCSharpType(colType);
sb.AppendLine($" public {propertyType} {colName} {{ get; set; }}");
}
sb.AppendLine(" }\n}");
return sb.ToString();