Fluent NHibernate数据库优先配置



我是Fluent Nhibernate的新手。我们已经开始将其用于数据访问的后台应用程序。

客户端已经有一个数据库,所以我们想使用数据库优先的方法,因为我们不想生成表。

对于概念验证解决方案,我使用了以下会话工厂配置

var oracleConfiguration = OracleDataClientConfiguration.Oracle10.ConnectionString("Data Source=MyDB;User Id=MyUserName; Password=myPassword; Pooling=true");
        return Fluently.Configure()
                       .Database(oracleConfiguration)
                       .Mappings(m => m.FluentMappings.Add<NhtestMap>())
                       .ExposeConfiguration((config) => { new SchemaExport(config).Create(false, true); })
                       .BuildSessionFactory();

由于在运行此代码之前,我的数据库中已经有了这个表,因此方法"ExposeConfiguration"已经删除了测试表"NHTest"。

我读了几篇博客,知道此方法在首次运行时创建表(这是代码优先方法的必需行为(。但对我们来说,使用 DB First 方法,我们不想删除或创建表。

有人可以帮助我正确配置数据库优先方法的会话工厂吗?

试试这个:

var oracleConfiguration = OracleDataClientConfiguration.Oracle10.ConnectionString("Data Source=MyDB;User Id=MyUserName; Password=myPassword; Pooling=true");
        return Fluently.Configure()
                       .Database(oracleConfiguration)
                       .Mappings(m => m.FluentMappings.Add<NhtestMap>())
//  Remove this line //.ExposeConfiguration((config) => { new SchemaExport(config).Create(false, true); })
                       .BuildSessionFactory();

最新更新