Hmm...
I do it this way:
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.JetDriver.JetDialect");
my whole configuration:
Code:
private NHibernate.Cfg.Configuration ConfigureDatabase()
{
//http://nhibernate.sourceforge.net/NHibernateEg/NHibernateEg.Tutorial1A.html#NHibernateEg.Tutorial1A-Configuration
// Enable the logging of NHibernate operations
log4net.Config.XmlConfigurator.Configure();
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider,
"NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass,
"NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
switch (dbType)
{
case MSACCESS2003:
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.JetDriver.JetDialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.JetDriver.JetDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConnectionToDb);
// "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _ConnectionToDb + ";User-Id=admin;Password=" + _Password + ";");
break;
case MSACCESS2007:
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.JetDriver.JetDialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.JetDriver.JetDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConnectionToDb);
// "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + _ConnectionToDb + ";Jet OLEDB:Database Password=" + _Password + ";");
break;
case MSSQL2008://MSSQL
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2000Dialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConnectionToDb);
break;
case MSSQLCE:
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSqlCeDialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlServerCeDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConnectionToDb);
break;
}
cfg.AddAssembly("Database");
MemoryStream stream = new MemoryStream();
////Ask NHibernate to use fields instead of Properties
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; //Enable Validation
NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "_ConnectionToDb.camelcase-underscore";
// Gather information from this assembly (can also be done class by class)
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(stream,
System.Reflection.Assembly.GetExecutingAssembly());
stream.Position = 0;
cfg.AddInputStream(stream); // Send the Mapping information to NHibernate Configuration
stream.Close();
return cfg;
}
Only SQL-CE and Access2003 are in progress at the moment...