NHibernate configuration to connect to Visual FoxPro 8.0?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 18:48:10

问题


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!


回答1:


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!




回答2:


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




回答3:


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"));
    }
}


来源:https://stackoverflow.com/questions/4106470/nhibernate-configuration-to-connect-to-visual-foxpro-8-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!