NHibernate configuration to connect to Visual FoxPro 8.0?
Curious if anyone out there has ever connected NHibernate to Visual Foxpro 8.0? I'm looking to hook into a legacy data store, and would prefer to use NHibernate vs. having to hand-cod开发者_C百科e all of the ADO.Net.
If anyone has an example of the configuration XML file for a FoxPro 8 connection that would be great!
And figured out the solution:
First, I needed to pick up the Visual FoxPro drivers (these are 9.0 but allowed me to work in 8.0).
Next, I had to set up my NHibernate config as follows. In this project I'm directory based, so I have a directory called C:\Temp\VisualFox\ that contains all of my *.dbf files.
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<reflection-optimizer use="false" />
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.GenericDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property>
<property name="connection.connection_string">Provider=VFPOLEDB;Data Source=C:\Temp\VisualFox;Collating Sequence=general</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
And now, all is well in the world!
I don't have a full XML example, but using the OleDbDriver
along with GenericDialect
should get you started.
Here is my solution:
var connectionString = @"Provider=VFPOLEDB.1;Data Source={0};CodePage=850".FormatWith(directory);
var cfg = new Configuration()
.DataBaseIntegration(c =>
{
c.Dialect<GenericDialect>();
c.ConnectionString = connectionString;
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
c.BatchSize = 100;
c.Driver<OleDbDriver>();
});
cfg.AddMapping(GetMappings());
and Config maps:
public class MyClassMap: ClassMapping<MyClass>
{
public MyClassMap(string filename)
{
Table("[" + filename + "]");
Id(e => e.LineNo, m => m.Column("Line_No"));
}
}
精彩评论