ORM tool: nhib.pdf (2) use CodeSmith to quickly generate ing files and ing

Source: Internet
Author: User
In the previous article "ORM tool: nhib.pdf (1)", we gave a brief introduction to nhib.pdf. The next series of articles will share with you the initial use of nhib.pdf in the form of a Demo. I. CodeSmith Introduction This article describes how to use this software to automatically generate a NHibernate ing file and an instance of the nhing class.

In the previous article "ORM tool: nhib.pdf (1)", we gave a brief introduction to nhib.pdf. The next series of articles will share with you the initial use of nhib.pdf in the form of a Demo. I. CodeSmith Introduction This article describes how to use this software to automatically generate a NHibernate ing file and an instance of the nhing class.

In the previous article "ORM tool: nhib.pdf (1)", we gave a brief introduction to nhib.pdf. The next series of articles will share with you the initial use of nhib.pdf in the form of a Demo.

Introduction to CodeSmith

This document uses tablesAutomatically generate the NHibernate ing file and ing class instanceDescribe how to use the software.

CodeSmithYesTemplate-based code generation toolsIt uses a syntax similar to ASP. NET to generate any type of code and files. CodeSmith can be used to generate anything including a simple set of strong types and a complete application. (Weak type-if there is no obvious type, the type will be automatically changed according to the environment; strong type-specifies its data type during Declaration to ensure class security, although the system also has a certain default conversion, it is not as casual as the weak type)

When you generate an application, you often need to repeat some specific tasks, such as writing data access code or generating a custom set. CodeSmith is especially useful in these cases because you can write templates to automatically complete these tasks, which not only improves your work efficiency, but also automatically complete the most boring tasks. CodeSmith comes with many templates, including templates corresponding to all. NET Collection types and templates used to generate stored procedures. But the real power of this tool is the ability to create custom templates.

2. Software Download

1. Download The CodeSmith code auxiliary generator

This article uses CodeSmith6.5.0 to crack and install it.

2. Download a component of the nhib1_template

Because I want to generate a nhing file and class of NHibernate, but this software does not come with it, I need to download a component of nhibernate_template, as shown in:

(3) Operation Process

0. Use SQLServer2008 to create a nhib.pdf database. The table "Person" has the following structure:

1. Use CodeSmith to generate the NHibernate ing file and ing Class

Click the nhib.pdf. cst file ,:

OutputDireatory: file output path

SourceDatabase: database files to be read

ForceId: True forces all tables in the database nhib.pdf to have a primary key.

Namespace: Namespace

RemoveTablePrefix: Default

Select the database-Add

Test TestConnection After configuring the database connection information:

Because we are operating on the SQLServer2008 database, select SqlSchemaProver here. If you are using other databases, you can choose one.

The link string is automatically generated.

Click Generate to automatically Generate the ing file and ing Class ,:

3. Analyze Person. hbm. xml

By viewing the automatically generated Person ing file Person. hbm. xml, let's take a look at how the object maps to the table:

 
   
  
      
   
   
    
    
       
   
   
    
   
  
 

This is the general usage of the nhing file and ing Class (that is, the Entity we have handwritten) generated by the table automatically. Isn't it easy ?! Saves a lot of manual work.

In the next article, we will use the generated Person ing file and ing Class in the Demo of the NHibernate tutorial. Please wait!

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.