<?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>
[ActiveRecord("Users")]
public class User : ActiveRecordBase

{
private int _id;
private string _name;
private string _password;
private string _emailAddress;
private DateTime _lastLogon;
[PrimaryKey(PrimaryKeyType.Identity, "LogonID")]
public int Id
{
get
{ return _id; }
set
{ _id = value; }
}
[Property("LogonName")]
public string Name
{
get
{ return _name; }
set
{ _name = value; }
}
[Property("Password")]
public string Password
{
get
{ return _password; }
set
{ _password = value; }
}
[Property("EmailAddress")]
public string Address
{
get
{ return _emailAddress; }
set
{ _emailAddress = value; }
}
[Property("LastLogon")]
public DateTime LastLogon
{
get
{ return _lastLogon; }
set
{ _lastLogon = value; }
}
}
[Serializable]
public class Person

{
private int id;
private string firstName;
private string lastName;
private DateTime? birthDate;
private double? weightInKilograms;
private double? heightInMeters;
public Person()
{ }
public int Id
{
get
{ return id; }
set
{ id = value; }
}
public string FirstName
{
get
{ return firstName; }
set
{ firstName = value; }
}
public string LastName
{
get
{ return lastName; }
set
{ lastName = value; }
}
public DateTime? BirthDate
{
get
{ return birthDate; }
set
{ birthDate = value; }
}
public double? WeightInKilograms
{
get
{ return weightInKilograms; }
set
{ weightInKilograms = value; }
}
public double? HeightInMeters
{
get
{ return heightInMeters; }
set
{ heightInMeters = value; }
}
}
学习资源
五.DAAB
public string GetCustomerList()

{
// 创建Database对象
Database db = DatabaseFactory.CreateDatabase();
// 使用SQL语句创建DbCommand对象
string sqlCommand = "Select CustomerID, Name, Address, City, Country, PostalCode " +
"From Customers";
DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
StringBuilder readerData = new StringBuilder();
// 调用ExecuteReader方法
using (IDataReader dataReader = db.ExecuteReader(dbCommand))

{
while (dataReader.Read())
{
// Get the value of the 'Name' column in the DataReader
readerData.Append(dataReader["Name"]);
readerData.Append(Environment.NewLine);
}
}
return readerData.ToString();
}
[Table(Name="Customers")]
public class Customer


{
[Column(Id=true)]
public string CustomerID;
[Column]
public string City;
}
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="Person" xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<alias>
<typeAlias alias="Person" type="IBatisNetDemo.Domain.Person,IBatisNetDemo" />
</alias>
<resultMaps>
<resultMap id="SelectAllResult" class="Person">
<result property="Id" column="PER_ID" />
<result property="FirstName" column="PER_FIRST_NAME" />
<result property="LastName" column="PER_LAST_NAME" />
<result property="BirthDate" column="PER_BIRTH_DATE" />
<result property="WeightInKilograms" column="PER_WEIGHT_KG" />
<result property="HeightInMeters" column="PER_HEIGHT_M" />
</resultMap>
</resultMaps>
<statements>
<select id="SelectAllPerson" resultMap="SelectAllResult">
select
PER_ID,
PER_FIRST_NAME,
PER_LAST_NAME,
PER_BIRTH_DATE,
PER_WEIGHT_KG,
PER_HEIGHT_M
from PERSON
</select>
<select id="SelectByPersonId" resultClass="Person" parameterClass="int">
select
PER_ID,
PER_FIRST_NAME,
PER_LAST_NAME,
PER_BIRTH_DATE,
PER_WEIGHT_KG,
PER_HEIGHT_M
from PERSON
where PER_ID = #value#
</select>
<insert id="InsertPerson" parameterclass="Person" >
<selectKey property="Id" type="post" resultClass="int">
${selectKey}
</selectKey>
insert into Person
( PER_FIRST_NAME,
PER_LAST_NAME,
PER_BIRTH_DATE,
PER_WEIGHT_KG,
PER_HEIGHT_M)
values
(#FirstName#,#LastName#,#BirthDate#, #WeightInKilograms#, #HeightInMeters#)
</insert>
<update id="UpdatePerson" parameterclass="Person">
<![CDATA[ update Person set
PER_FIRST_NAME =#FirstName#,
PER_LAST_NAME =#LastName#,
PER_BIRTH_DATE =#BirthDate#,
PER_WEIGHT_KG=#WeightInKilograms#,
PER_HEIGHT_M=#HeightInMeters#
where
PER_ID = #Id# ]]>
</update>
<delete id="DeletePerson" parameterclass="Person">
delete from Person
where
PER_ID = #Id#
</delete>
</statements>
</sqlMap>
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; }
