When a soft code generator generates an object, modify the template to simplify entity encapsulation. The Code Generator entity
First, right-click the Code Template and choose create template.
<# @ Template language = "c #" HostSpecific = "True" #> <# @ output extension = ". cs "#> <# TableHost host = (TableHost) (Host); host. fieldlist. sort (CodeCommon. compareByintOrder); #> using System; using System. text; using System. collections. generic; using System. data; namespace <# = host. nameSpace #>. model <# if (host. folder. length> 0) {#>. <# = host. folder #> <#}#>{< # if (host. tableDescription. length> 0) {#>// <# = Host. tableDescription #> <#}#> public class <# = host. getModelClass (host. tableName) # >{< # foreach (ColumnInfo c in host. fieldlist) {#>/// <summary> /// <# = string. isNullOrEmpty (c. description )? C. columnName: c. description #> // </summary> public <# = GetTypeName (c) #> <# = c. columnName #>{ get; set ;}###>}< # + private string GetTypeName (ColumnInfo c)
{
If (CodeCommon. DbTypeToCS (c. TypeName). ToString (). Trim (). ToLower ())! = "String") // if the field can be empty and cannot be converted to an empty string
{
Return CodeCommon. DbTypeToCS (c. TypeName) + "? ";
}
Else
{
Return CodeCommon. DbTypeToCS (c. TypeName );
}
} #>
Paste and save the code.
Usage:
1. Click the template we just created
2. Click Generate code.
The generated code is like this.
Public class User_Users {// <summary>
/// UserId
/// </Summary>
Public int? UserId {get; set ;}
/// <Summary>
/// Employee name
/// </Summary>
Public string UserName {get; set ;}
/// <Summary>
/// English name
/// </Summary>
Public string EnglishName {get; set ;}
/// <Summary>
/// Password
/// </Summary>
Public string PassWord {get; set ;}
/// <Summary>
/// Employee ID
/// </Summary>
Public string JobNumber {get; set ;}
/// <Summary>
/// Position
/// </Summary>
Public string Position {get; set ;}}