Back to directory
During project development, a problem occurs: after a new non-empty field is added, the original program logic needs to be modified again to add the original field to the program, this approach is not widely advocated. Therefore, I used the T4 template to make minor changes to the original entity class, which solved this problem, that is, adding default values to non-empty attributes in the object, in fact, there are several types, such as the default value of string. empty, int, short, and long are all 0 by default, while datetime is the current date by default, which can be completed in the T4 module.
Take a look at the code
<# = Code. escape (entity) #> <(edmProperty>. <# = code. escape (edmProperty) # >=< # = typeMapper. createLiteral (edmProperty. defaultValue) #> <(navigationProperty>. <# = code. escape (navigationProperty) #> = HashSet <# = typeMapper. getTypeName (navigationProperty. toEndMember. getEntityType () # >>< (complexProperty>. <# = code. escape (complexProperty) # >=< # = typeMapper. getTypeName (complexProperty. typeUsage) #> <>
Save the template and check the generated class.
Back to directory