Fluent NHibernate - 如何为 oracle 配置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/562926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:50:22  来源:igfitidea点击:

Fluent NHibernate - how to configure for oracle?

oraclenhibernatefluent-nhibernate

提问by George Mauer

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

几乎可以肯定是一个愚蠢的问题,但我在任何地方都找不到答案。

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

入门教程中,数据库是 SQLite,因此他的会话工厂创建是使用 FluentNHibernate.Cfg.Db 命名空间中的 SQLiteConfiguration 类完成的

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

伟大的!但是我没有看到用于使用 Oracle 数据库的 Configuration 类。我该怎么做呢?

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

交叉发布到fluent NH 邮件列表(附答案)

采纳答案by kimsk

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

回答by Alex Reitbort

Does this helps you?

这对你有帮助吗?

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

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 _configfield. You can safely, add the field to the OracleConnectionStringExpression class and remove it.

编辑:提到的代码使用了在 Fluent NHibernate 中不再存在的 ConnectionStringExpression 类。但是,该类除了保存OracleConfiguration _config字段外不用于任何其他用途。您可以安全地将该字段添加到 OracleConnectionStringExpression 类并将其删除。

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.

剩下的问题是 NHibernate 现在会出于某种原因寻找不在当前版本的 Oracle.DataAccess 中的组件。如果你想解决这个问题,你可以像累博主在这里做的那样。