how to setup nhibernate configuration (fluent configuration) for MySql and force the default engine to be InnoDB so Im able to use Transactions
thanks
Or you may want to use this custom dialect
public class MySQL5InnoDBDialect
: MySQL5Dialect
{
public MySQL5InnoDBDialect()
{
RegisterColumnType(DbType.Guid, "CHAR(36)"); //You don't "really" need this one for what you asked
}
public override string TableTypeString
{
get { return " ENGINE=InnoDB"; }
}
public override bool HasSelfReferentialForeignKeyBug
{
get { return true; }
}
public override bool SupportsCascadeDelete
{
get { return true; }
}
}
(update your .config file accordingly)
<property name="dialect">
Org.Zighinetto.MySQL5InnoDBDialect, Org.Zighinetto
</property>
The dialect trick works fine when you don't own MySQL installation (ie. you use shared hosting) and default is the usual MyISAM
Generally there is nothing specific that you would have to do with your mappings to work with mysql and innodb.
Switching to innodb engine is something you will have to do from inside of mysql yourself, it is not related to nHibernate. http://dev.mysql.com/doc/refman/5.1/en/storage-engine-setting.html
Here is a sample configuration that I use for mysql (innodb) and nHibernate:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source=localhost;Database=test;UID=root;pwd=;</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="show_sql">false</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="hbm2ddl.keywords">none</property>
</session-factory>
</hibernate-configuration>