ORM tool: nhibsmith (2) use CodeSmith to quickly generate ing files and ing classes. ormcodesmith

Source: Internet
Author: User

ORM tool: nhibsmith (2) use CodeSmith to quickly generate ing files and ing classes. ormcodesmith

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:

<? Xml version = "1.0" encoding = "UTF-8"?> <Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.0"> <! -- The object Person establishes a ing relationship with the table t_Person --> <class name = "Test. Model. Person, Test. Model" table = "t_Person"> <! -- The Id attribute of the object Person establishes a ing relationship with the t_Id field in the t_Person table --> <id name = "Id" type = "Int32" unsaved-value = "null"> <column name = "t_Id" length = "4" SQL-type = "int" not-null = "true" unique = "true"/> <generator class = "native"/> </id> <! -- The Name attribute of the object Person establishes a ing relationship with the t_Name field in the t_Person table --> <property name = "Name" type = "String"> <column name = "t_Name" length =" 50 "SQL-type =" varchar "not-null =" false "/> </property> </class> 


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!






It is not allowed to generate a database through the nhib.pdf ing file.

Have you backed up?
If you don't have one, you will be ruined.
Khan
It doesn't matter.
If you need such software, I 'd be happy to help you find it.
Add me to 669614515
 
How to Use CodeSmith to automatically generate the NHibernate object class and hbmxml File

(1) CodeSmith uses V2.5 (2) to put the entire NHibernateTemplate folder under C: \ Program Files \ CodeSmith \ v2.5 \ Samples. (3) provide Oracle Support. Use VS2003 to open the OracleNativeSchemaProvider project. The project must reference SchemaExplorer. dll, which can be found under C: \ Program Files \ CodeSmith \ v2.5. After re-compilation, copy the compiled SchemaExplorer. OracleNativeSchemaProvider. dll and SchemaExplorer. OracleNativeSchemaProvider. dll. config file C: \ Program Files \ CodeSmith \ v2.5 and re-open CodeSmith. The location of CodeSmith 4.0 is not like this (4) nhibctions configuration example: <configSections <sectionname = "nhibctions" type = "System. configuration. nameValueSectionHandler, System, Version = 1.0.5000.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "/</configSections <nhibctions <addkey =" hibernate. connection. provider "value =" nhib.pdf. connection. driverConnectionProvider "/<addkey =" hibernate. connection. driver_class "value =" nhib.pdf. driver. else l EClientDriver "/<addkey =" hibernate. connection. connection_string "value =" userid = XTGL; datasource = ORCL; password = GSGL "/<addkey =" hibernate. connection. isolation "value =" ReadCommitted "/<addkey =" hibernate. dialect "value =" nhib.pdf. dialect. oracle9Dialect "/</nhibernate (5) Use SessionQuicker to operate the NHibernate data layer. Solutions not supported by Chinese characters:

Related Article

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.