1. Installer
Castleproject-1.0-rc2.msi (download and install it !).
2. modify the configuration of Web. Config
In Web. Config, you must add the configuration under the node <configSections>.
<Section name = "activerecord"
Type = "Castle. ActiveRecord. Framework. Config. ActiveRecordSectionHandler, Castle. ActiveRecord"/>
The <section> node activerecord is added above, and the specific attribute value of activerecord is configured.
<Activerecord>
<Config>
<Add key = "hibernate. connection. driver_class"
Value = "nhib.pdf. Driver. SqlClientDriver"/>
<Add key = "hibernate. dialect"
Value = "nhibect. Dialect. MsSql2000Dialect"/>
<Add key = "hibernate. connection. provider"
Value = "nhib.pdf. Connection. DriverConnectionProvider"/>
<Add key = "hibernate. connection. connection_string"
Value = "Data Source =.; Initial Catalog = test; Integrated Security = SSPI"/>
</Config>
</Activerecord>
3. Read configuration information and automatically create a data table based on the ing relationship
Add a Global service program Global. asax to the web Project and configure the Global service in the application.
First introduce the namespace
<% @ Application Language = "C #" %>
<% @ Import Namespace = "Castle. ActiveRecord. Framework" %>
<% @ Import Namespace = "Castle. ActiveRecord" %>
Void Application_Start (object sender, EventArgs e)
{
// Code that runs when the application starts
IConfigurationSource source = ConfigurationManager. GetSection ("activerecord") as IConfigurationSource;
ActiveRecordStarter. Initialize (source, typeof (ZDS. Test. Model. Users ));
// In the above Initialize () method, the reflection mechanism can be used to track the Assembly. In this example, the Users class
// ActiveRecordStarter. Initialize (source, typeof (ZDS. Test. Model. Users); you can track the entire set of programs.
// (Trace an assembly through Reflection <introduce namespace System. Reflection first> or use full reference) the code is as follows:
// ActiveRecordStarter. Initialize (System. Reflection. Assembly. load ("ZDS. DaiTao. Test. Model", source );
ActiveRecordStarter. CreateSchema ();
// The above sentence does not work much, but it is very important. You only need to establish the relationship in the object Layer class. With this code, you can directly create a database table. You only need
When a database is created, the table is automatically created (using the class as the table name and ing as the field name ...)
}
This is basically the case.