Castle learning notes -- Castle. AvtiveRecord Configuration

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.