使用InnoDB引擎的NHibernate流畅配置mysql

时间:2011-07-13 02:07:06

标签: mysql nhibernate innodb

如何为MySql设置nhibernate配置(流畅配置)并强制默认引擎为InnoDB,以便我能够使用事务

感谢

2 个答案:

答案 0 :(得分:2)

或者您可能想要使用此自定义方言

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; }
        }
    }

(相应地更新.config文件)

<property name="dialect">
Org.Zighinetto.MySQL5InnoDBDialect, Org.Zighinetto
</property>

当你没有MySQL安装时(即你使用共享主机),默认是通常的MyISAM

,方言技巧很好用

答案 1 :(得分:0)

一般来说,使用mysql和innodb进行映射没有任何具体内容。

切换到innodb引擎是你必须自己在mysql内部做的事情,它与nHibernate无关。 http://dev.mysql.com/doc/refman/5.1/en/storage-engine-setting.html

这是我用于mysql(innodb)和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>