2010-11-05 63 views
2

好奇如果有人曾經把NHibernate連接到Visual Foxpro 8.0?我正在考慮掛鉤遺留數據存儲,並且寧願使用NHibernate而不必手動編寫所有的ADO.Net。連接到Visual FoxPro 8.0的NHibernate配置?

如果任何人都有一個FoxPro 8連接的配置XML文件的例子,那將非常棒!

回答

3

,並計算出瞭解決方案:

首先,我需要拿起Visual FoxPro drivers(這些都是9.0,但允許我在8.0工作)。

接下來,我必須設置我的NHibernate配置如下。在這個項目中,我是基於目錄的,因此我有一個名爲C:\ Temp \ VisualFox \的目錄,其中包含我所有的* .dbf文件。

<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> 

現在,一切都很好!

1

我沒有完整的XML示例,但使用OleDbDriver以及GenericDialect可以幫助您入門。

+0

讓我給一個鏡頭! – 2010-11-05 16:34:30

1

這裏是我的解決方案:

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()); 

和配置地圖:

public class MyClassMap: ClassMapping<MyClass> 
{ 
    public MyClassMap(string filename) 
    { 
     Table("[" + filename + "]"); 
     Id(e => e.LineNo, m => m.Column("Line_No")); 
    } 
}