I wrote an article about AR configuration a few days ago. I wrote it after I made a small instance for a friend who just learned AR. I used IConfigurationSource, activeRecord is in the web. as configured in config, ActiveRecord can be written elsewhere or dynamically configured. For example, it can be configured using XML or Hashtable. next I will briefly introduce how to configure it.
1. Use XML configuration to obtain configuration information through XmlConfigurationSource. For detailed configuration, see the following xml data.
1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <activerecord>
3 <config>
4 <add
5 key = "hibernate. connection. driver_class" value = "nhib.pdf. Driver. SqlClientDriver"/>
6 <add
7 key = "hibernate. dialect" value = "NHibernate. Dialect. MsSql2000Dialect"/>
8 <add
9 key = "hibernate. connection. provider" value = "nhib.pdf. Connection. DriverConnectionProvider"/>
10 <add
11 key = "hibernate. connection. connection_string" value = "Data Source =.; Initial Catalog = test; Integrated Security = SSPI"/>
12 </config>
13 </activerecord>
14
XmlConfigurationSource source = new XmlConfigurationSource ("../appconfig. xml ");
2. Use Hashtable to implement configuration. Use InPlaceConfigurationSource to obtain configuration information.
1 Hashtable properties = new Hashtable ();
2properties. Add ("hibernate. connection. driver_class", "nhib.pdf. Driver. SqlClientDriver ");
3properties. Add ("hibernate. dialect", "nhibect. Dialect. MsSql2000Dialect ");
4properties. Add ("hibernate. connection. provider", "nhib.pdf. Connection. DriverConnectionProvider ");
5properties. Add ("hibernate. connection. connection_string", "Data Source =.; Initial Catalog = test; Integrated Security = SSPI ");
6 InPlaceConfigurationSource source = new InPlaceConfigurationSource ();
7source. Add (typeof (ActiveRecordBase), properties );
The above two methods can be used to configure ActiveRecord. I prefer the second method, Hashtable, in general applications, there is actually no difference. I wrote a general method in the company a few days ago to reflect the gap. We should all know that modifying strings is easier than modifying XML, take the above "Data Source = .; initial Catalog = test; Integrated Security = SSPI "database connection string, if you write the ActiveRecord configuration on the Web. in the config or XML file, when you create a program, you need to configure a web. config node or add an XML file. Here I think of writing a general method to solve this problem, when I need to program, I only need to input the database name and the Entity Data assembly of the program. Other work is called to the encapsulated method for processing.
For more information about solutions for ActiveRecord configuration encapsulation, click the following article to connect
ActiveRecord configuration encapsulation Solution
Http://www.cnblogs.com/beniao/archive/2007/12/01/979087.html