i have to use a custom odbc driver.
All i need to pass as a connection string is the DSN.
How do i do this with (fluent)nhibernate? FluentNHibernate.Cfg.Db does only offer a OdbcConnectionStringBuilder class with an DSN method. How do i use this?
You can create your own OdbcConfiguration
class that derives from PersistenceConfiguration
.
Depending on your database, you will have to replace the Dialect in the following class.
public class OdbcConfiguration :
PersistenceConfiguration<OdbcConfiguration,
FluentNHibernate.Cfg.Db.OdbcConnectionStringBuilder>
{
protected OdbcConfiguration()
{
Driver<NHibernate.Driver.OdbcDriver>();
}
public static OdbcConfiguration MyDialect // <-- insert any name here
{
get
{
// insert the dialect you want to use
return new OdbcConfiguration().Dialect<NHibernate.Dialect.MyDialect>();
}
}
}
Then, in Fluent NHibernate, use that OdbcConfiguration
:
// replace MyDialect here, too
Fluently.Configure()
.Database(OdbcConfiguration.MyDialect.ConnectionString("DSN=...;UID=...;PWD=...")
.Driver<NHibernate.Driver.OdbcDriver>()
.Dialect<NHibernate.Dialect.MyDialect>() // <-- again, change this
.etc...
Didn't find any sample code using OdbcConnectionStringBuilder after a quick search. Fluent NHibernate doesn't seem to have a corresponding "OdbcConfiguration" object to use with the OdbcConnectionStringBuilder. If you don't use Fluent NHibernate for configuring the database (you can still use Fluent for all the object mapping though), you can configure via the hibernate.cfg.xml file, look at the DB2 example config for using ODBC provider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With