一.创建Web工程
创建一个Web站点或者Web应用程序,添加对Castle.ActiveRecord.dll的引用。
二.创建需要持久化的业务实体
在.NET2.0下,由于引入了泛型,创建业务实体比1.1下简单了许多,业务实体只需要继承于泛型的ActiveRecordBase类,其中默认已经实现了一些静态的方法,不需要我们再在业务实体中实现。
[ActiveRecord("Employees")]
public class Employee : ActiveRecordBase<Employee>
{
private string employeeID;
private string lastName;
private string city;
private string address;
private string homePhone;
private string country;
[PrimaryKey(PrimaryKeyType.Assigned)]
public string EmployeeID
{
get { return employeeID; }
set { employeeID = value; }
}
[Property]
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
[Property]
public string City
{
get { return city; }
set { city = value; }
}
[Property]
public string Address
{
get { return address; }
set { address = value; }
}
[Property]
public string HomePhone
{
get { return homePhone; }
set { homePhone = value; }
}
[Property]
public string Country
{
get { return country; }
set { country = value; }
}
}