1

I am new to Fluent Nhibernate. We have started using it for a Back office application for Data Access.

The client already has a Database with them so we would like to use the Database first approach as we don't want to generate tables.

For a Proof of concept solution, I used the below Session Factory configuration

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

Since I already have this table in my DB before running this code, the method 'ExposeConfiguration' has dropped the test table 'NHTest'.

I read few blogs and came to know that this method creates table on first run (Which is the required behavior for Code First approach). But for us, with the DB First approach, we don't want to drop or create tables.

Can some one please help me out to correctly configure the Session Factory for DB First approach ?

1
  • 3
    remove the line .ExposeConfiguration(...) Commented Apr 6, 2017 at 13:38

1 Answer 1

2

Try this:

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.