摘要:前几天在回答一个问题时,我是凭直感回答的,因为没试过。正好最近对O/R Mapper感兴趣,所以决定试一下NHibernate,发现其Quick Start Guide 有几个地方不是很清楚,现在把试验的步骤记录如下。(因为试验的这台机器没有VS.NET,所以用了csc.exe来直接编译)
0. 安装
NHibernate
http://sourceforge.net/project/showfiles.php?group_id=73818
log4net
http://sourceforge.net/project/showfiles.php?group_id=31983&release_id=171808
1. 生成数据库
use master
go
create database NHibernate
go
use NHibernate
go
CREATE TABLE users (
LogonID nvarchar(20) NOT NULL default '0',
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go
2. 生成persistent类: User.cs
using System;
//note, in the Quick Guide, it says NHibernate.Demo.QuickStart
//you could use it, then you need to change the class name in
//the User.hbm.xml file
namespace NHibernate.Examples.QuickStart
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
......[
阅读全文]