主要修改Database.tt这个文件
优化点:
1.修改默认参数;
2.修改实体类名成为首字母大写的驼峰式写法,自动去掉下划线;
3.修改字段为首字母大写的驼峰式写法,自动去掉下划线;
<#@ include file="PetaPoco.Core.ttinclude" #>
<#
// Settings
ConnectionStringName = ""; // Uses last connection string in config if not specified
Namespace = "";
RepoName = "";
GenerateOperations = true;
GeneratePocos = true;
GenerateCommon = true;
ClassPrefix = "";
ClassSuffix = "";
TrackModifiedColumns = false;
ExplicitColumns = true;
ExcludePrefix = new string[] {}; // Exclude tables by prefix.
// Read schema
var tables = LoadTables();
/*
// Tweak Schema
tables["tablename"].Ignore = true; // To ignore a table
tables["tablename"].ClassName = "newname"; // To change the class name of a table
tables["tablename"]["columnname"].Ignore = true; // To ignore a column
tables["tablename"]["columnname"].PropertyName="newname"; // To change the property name of a column
tables["tablename"]["columnname"].PropertyType="bool"; // To change the property type of a column
*/
foreach(Table tbl in from t in tables select t)
{
//处理表名称
string srcStr = tbl.Name.ToLower();
string newString = "";
int first = 0;
while (srcStr.IndexOf("_") != -1)
{
first = srcStr.IndexOf("_");
if (first != srcStr.Length)
{
newString = newString + srcStr.Substring(0, first);
srcStr = srcStr.Substring(first + 1);
srcStr = srcStr.Substring(0, 1).ToUpper() + srcStr.Substring(1);
}
}
newString = newString + srcStr;
tables[tbl.Name].ClassName =ClassPrefix+newString.Substring(0, 1).ToUpper() + newString.Substring(1)+ClassSuffix;
//处理字段名称
foreach(Column col in from c in tbl.Columns select c)
{
if(col.Name.StartsWith("_"))
{
tables[tbl.Name][col.Name].Ignore=true;
}
string srcStrCol = col.Name.ToLower();
string newStringCol = "";
int firstCol = 0;
while (srcStrCol.IndexOf("_") != -1)
{
firstCol = srcStrCol.IndexOf("_");
if (firstCol != srcStrCol.Length)
{
newStringCol = newStringCol + srcStrCol.Substring(0, firstCol);
srcStrCol = srcStrCol.Substring(firstCol + 1);
srcStrCol = srcStrCol.Substring(0, 1).ToUpper() + srcStrCol.Substring(1);
}
}
newStringCol = newStringCol + srcStrCol;
tables[tbl.Name][col.Name].PropertyName=newStringCol.Substring(0, 1).ToUpper() + newStringCol.Substring(1);
}
}
// Generate output
if (tables.Count>0)
{
#>
<#@ include file="PetaPoco.Generator.ttinclude" #>
<# } #>