Castle Active Record for .NET2.0快速入门示例
[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; }
}
}
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/>
</configSections>
<connectionStrings>
<add name="NorthWind" connectionString="Data Source=RJ-097;Initial Catalog=Northwind;User ID=sa;Password=sa"/>
</connectionStrings>
<activerecord isWeb="true">
<config>
<add key="hibernate.connection.driver class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.connection.connection_string" value="ConnectionString = ${NorthWind}"/>
</config>
</activerecord>
</configuration>
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Castle.ActiveRecord.Framework.IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as Castle.ActiveRecord.Framework.IConfigurationSource;
Castle.ActiveRecord.ActiveRecordStarter.Initialize(typeof(Employee).Assembly, source);
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html>
<head runat="server">
<title>Castle Active Record for 2.0快速入门示例</title>
</head>
<body>
<form id="form1" runat="server">
<h1>Castle Active Record for 2.0快速入门示例</h1>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField HeaderText="Employee ID" DataField="EmployeeID" />
<asp:BoundField HeaderText="LastName" DataField="LastName" />
<asp:BoundField HeaderText="City" DataField="City" />
<asp:BoundField HeaderText="Address" DataField="Address" /> 
<asp:BoundField HeaderText="HomePhone" DataField="HomePhone" />
<asp:BoundField HeaderText="Country" DataField="Country" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = Employee.FindAllByProperty("Country", "UK");
this.GridView1.DataBind();
}
本文出自 “TerryLee技术专栏” 博客,请务必保留此出处http://terrylee.blog.51cto.com/342737/67670
1人 |
了这篇文章 |