Several ideas about how to select table fields in codesmith

Source: Internet
Author: User

As you all knowCodesmithCurrently, the field selection function is not provided. We generateListIt is not possible to generate all fields in the entire table on the page. Therefore, it is necessary to implement the field selection function. I collected some information on the Internet, and there are basically the following implementation ideas:

1. Use Tableschema And Tableschemacollection . Save all fields in a data table and set an identifier. In the template, you can access these identifiers to control our output. This is simple,CodeExternal tools are required for generation. This external tool can be a small tool compiled by ourselves. You can set the identifier of the field to be generated.

2. If we use SQL Server Database, you can set the extension attributes on the column, and then use these extension attributes in the template to control the output. SQL Server Provides a stored procedure Sp_addextendedproperty To add extended attributes to objects in the database. This method is very difficult to implement. You need to add extended attributes to all objects used in the database, although you can also write a small tool to implement it, however, external tools are used again. For more information about how to use extended attributes, see CodesmithPractical Tips (4): use extended attributes

3. Still use Tableschema And use a custom property Stringcollection The dialog box removes some fields or tables. In the generated code, the field we need to generate is Sourcetable. Columns Remove Stringcollection list The part of the field. The implementation is relatively simple, but the disadvantage is that you need to manually enter the field or table name. In Codesmith Provided template exampleProgramThis implementation method is also used. About Stringcollection For more information, see CodesmithPractical skills (1): UseStringcollection

4. The last one is the support of the designer. It is also the ideal idea. It is to write a form based on your own needs through the custom attribute dialog box, which must inherit from Uitypeeditor Class. In this way, we can use Sqldmo To obtain information about objects in the database and provide a friendly field selection interface. The advantage of this method is needless to say. The disadvantage is that it is complicated to compile the form and it is difficult to implement it. For support for the designer, see CodesmithPractical Tips (11): Add designer support

 

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.