EF architecture ~ Add default values for all attributes in the T4 Template

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.