Recently to busy biennial, but still decided to take some empty every day to write Codesmith series of articles, in this really do not dare to use the words of the tutorial, after all, their own understanding of codesmith is not a lot, there are a lot of cattle in the blog Park published a lot of codesmith articles, But I still want to publish their own experience, I hope to give beginners more reference, the tutorial has errors or unclear places to welcome you point out, I will still uphold the style before, with as many diagrams as possible to explain the steps, because I think the text is more easily understood illustrations.
Okay, nonsense, let's start our codesmith journey, let me talk about the goal of this series of tutorials, as we all know, codesmith one of the powerful features is to generate batch code according to the template, which is also attracting many programmers to use it, it greatly saves the programming time , eliminating the large number of copy and paste waste operations.
First of all, since to explain how to use Codesmith and PowerDesigner rapid generation of bulk code, of course, the first to install the 2 software, the following simple talk about how to install the cracked 2 software bar, of course, the crack is only learning, please do not use for commercial use HA, to support the genuine, Everyone is doing software, know that developing a set of software is not easy ah.
Codesmith Installation Method:
1). Click to download the installation file
2). Run, install the steps will not say, select the directory you want to install, the next step is OK.
3). Run, select the Codesmith installation directory, all the way next, on the hack
Complete, then you can run the program at the beginning--codesmith Professional 5.1--codesmith Studio.
PowerDesigner Installation Method:
Http://jingyan.baidu.com/article/1974b289a836ccf4b1f77436.html
Install the 2 software, then start using it, or the same as before, first put forward the requirements, and then do the examples, because we use them, it must be because they can skillfully solve a problem, or why we spend so much time and hard disk space to install them.
Well, our present demand is: When a new project is received, the programmer only needs to design the database structure (table, table field, inter-table relationship) according to the project requirements, and then just press a key to get all the hierarchical schema code files based on the database immediately. in other words, we want to be able to get all the code we want without hitting one line of code ! And that's what these 2 software can do, and the purpose of installing them.
Well, the characters have already been introduced, and then see how they perform this wonderful show:
First we need to create a test database, for the sake of simplicity, we only create a Student table and a Major table in this database. Its table structure and relationships are as follows.
See how to create this database quickly with PowerDesigner.
1. Now start using PowerDesigner to create the database, first run the program, into the main interface:
2.file-new model-physical Data model-physical diagram-model name is set to test, the DBMS property is set to Microsoft SQL Server 2005:
3. First create a table template with the table tool:
4. Double-click the table template to set the properties, we first set up the Major table:
5. Set the table name, click the Columns tab, set the field properties, set:
6. Because the Majorid field we want to set to autogrow , so to set its advanced properties, select the Majorid field, click the Properties button, in the general panel tick the identity check box:
7. After determining we create a student table, the field settings:
8. Next is to create a Majorid foreign key for student, using PowerDesigner can easily do this work, select the Relationship Settings tool, on the student table, press and hold the left button, drag to the major table, You can add a Majorid foreign key for the student table:
9. Haha, now the test table has been set up, and then set up the database we want to generate, these tables will be created to the database, we are in the design panel blank right - -properties, in the Popup Property Settings dialog box set as follows:
10 OK, here we have the new database setup has been completed, but in SQL is still empty ah, how can we transfer this design structure to SQL Server 2005? Perform the operation:database-generate Database, Set the stored procedure export directory and file name, click OK:
11. To your export directory, you can see the exported database created stored procedures, open SQL, execute, you will see the database is magically created:
12. Well, the database preparation is ready, next we will use the database combined with Codesmith automatic batch generation code ~
The source code generated in the above practice:
/*==============================================================*/
/* Database Name:pd_test */
/* DBMS Name:microsoft SQL Server 2005 */
/* Created ON:2010/6/13 Sunday 17:27:17 */
/*==============================================================*/
Dropdatabase Pd_test
Go
/*==============================================================*/
/* Database:pd_test */
/*==============================================================*/
CreateDatabase Pd_test
Go
Use Pd_test
Go
/*==============================================================*/
/* Table:major */
/*==============================================================*/
CreateTable Major (
Majorid Intidentity,
Name nvarchar (notnull),
Remark nvarchar (Max) NULL,
Constraint pk_major PrimaryKey (Majorid)
)
Go
/*==============================================================*/
/* Table:student */
/*==============================================================*/
CreateTable Student (
StudentID nvarchar () notnull,
Majorid Intnull,
Name nvarchar (notnull),
Sex Bitnotnull,
Age Intnull,
Remark nvarchar (Max) NULL,
Constraint pk_student PrimaryKey (StudentID)
)
Go
Altertable Student
AddConstraint fk_student_reference_major ForeignKey (Majorid)
References Major (Majorid)
Go
Use of Codesmith and PowerDesigner installation and database creation