Fluent NHibernate - how to configure for oracle?

こ雲淡風輕ζ 提交于 2019-12-04 10:57:18

问题


Almost certainly a stupid question but I can't find the answer anywhere.

In the Getting Started tutorial the database is SQLite and so his session factory creation is done using the SQLiteConfiguration class in the FluentNHibernate.Cfg.Db namespace

Great! But I don't see a Configuration class for using an Oracle database. How do I do this?

Cross-posted to the fluent NH mailing list (with answer)


回答1:


This works for me. Hope this helps!

private static ISessionFactory CreateSessionFactory()
    {

        var cfg = OracleClientConfiguration.Oracle9
            .ConnectionString(c =>
                c.Is("DATA SOURCE=<<NAME>>;PERSIST SECURITY INFO=True;USER ID=<<USER_NAME>>;Password=<<PASSWORD>>"));

        return Fluently.Configure()
                .Database(cfg)
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CLASS_NAME>().ExportTo(@".\"))
                .ExposeConfiguration(BuildSchema)
        .BuildSessionFactory();
    }

    private static void BuildSchema(NHibernate.Cfg.Configuration config)
    {
        // this NHibernate tool takes a configuration (with mapping info in)
        // and exports a database schema from it
        new SchemaExport(config)
          .Create(false, true);
    }



回答2:


Does this helps you?

http://tiredblogger.wordpress.com/2008/12/04/persistanceconfiguration-for-oraclefluent-nhibernate/

Edit: The code mentioned uses the ConnectionStringExpression class which no longer exists in Fluent NHibernate. However, that class isn't used for anything other than holding the OracleConfiguration _config field. You can safely, add the field to the OracleConnectionStringExpression class and remove it.

The remaining issue is that NHibernate will now for some reason look for components that are not in the current build of Oracle.DataAccess. If you want to deal with that you can do what tiredblogger did here.



来源:https://stackoverflow.com/questions/562926/fluent-nhibernate-how-to-configure-for-oracle

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