NHibernate configuration to connect to Visual FoxP

2019-02-14 23:50发布

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-code all of the ADO.Net.

If anyone has an example of the configuration XML file for a FoxPro 8 connection that would be great!

3条回答
疯言疯语
2楼-- · 2019-02-15 00:07

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"));
    }
}
查看更多
Anthone
3楼-- · 2019-02-15 00:12

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
4楼-- · 2019-02-15 00:18

I don't have a full XML example, but using the OleDbDriver along with GenericDialect should get you started.

查看更多
登录 后发表回答