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