Turn: initial development of a three-tier Application Based on nhib.pdf This document does not describe how to use nhib.pdf in detail, but uses a simple example to demonstrate the three-tier structure application based on nhib.pdf.ProgramDevelopment process. DDL has been written in Chinese for the relevant documentation of nhib.pdf, but since the English documentation is not complete, it is not complete in Chinese. Bodhi talked about the difficulties in learning nhibana in an essay "The Road to nhibana learning". I also hope that you can share your experiences and experiences in using nhibana and share them with you. In addition, I was just getting started with nhigoal. If you have any errors, please give us some advice. Step 1: Prepare a data table Here, we use the simplest example: there is a user table, which contains the following fields: ID, name, password, email address, and last logon time. Create Table users (
Logonid varchar (20) primary key,
Name varchar (40 ),
Password varchar (20 ),
Emailaddress varchar (40 ),
Lastlogon datetime
) Step 2: Create a class to be persisted Create a nhibernatewebdemo. Model Project in. NET and add the user entity class. // User. CS
Using system;
Namespace nhibernatewebdemo. Model
{
Public class user
{
Public user ()
{
}
Private string ID;
Private string username;
Private string password;
Private string emailaddress;
Private datetime lastlogon;
Public String ID
{
Get {return ID ;}
Set {id = value ;}
}
Public String Username
{
Get {return username ;}
Set {username = value ;}
}
Public String Password
{
Get {return password ;}
Set {Password = value ;}
}
Public String emailaddress
{
Get {return emailaddress ;}
Set {emailaddress = value ;}
}
Public datetime lastlogon
{
Get {return lastlogon ;}
Set {lastlogon = value ;}
}
}
} Step 3: Create a persistent ing File The file is named user. HBM. xml and put in the same directory as user. CS. Set the file generation operation attribute to "embedded resource. In addition, the number is used as the primary key, which is input by the user. Therefore, assigned is used in the ing file. <? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.0">
<Class name = "nhibernatewebdemo. model. User, nhibernatewebdemo. Model" table = "users">
<ID name = "ID" column = "logonid" type = "string" length = "20">
<Generator class = "assigned"/>
</ID>
<Property name = "username" column = "name" type = "string" length = "40"/>
<Property name = "password" type = "string" length = "20"/>
<Property name = "emailaddress" type = "string" length = "40"/>
<Property name = "lastlogon" type = "datetime"/>
</Class>
</Hibernate-mapping> |