Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate - how to configure for oracle?

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)

like image 288
George Mauer Avatar asked Feb 04 '23 12:02

George Mauer


1 Answers

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);
    }
like image 116
kimsk Avatar answered Feb 06 '23 05:02

kimsk