我收到了MappingNHibernateException的错误消息:
{“无法编译映射文档:Infrastructure.DataAccess.Mappings.Post.hbm.xml”}
Could not find the dialect in the configuration
部分
Configuration configuration = new Configuration()
.AddAssembly("Infrastructure");
_sessionFactory = configuration.BuildSessionFactory();
有什么问题?
的hibernate.cfg.xml
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver </property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.connection_string">Server=localhost\SQLServer2005;database=NHibernate101;Integrated Security=True;</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="Infrastructure"></mapping>
</session-factory>
</hibernate-configuration>
答案 0 :(得分:0)
试试这个。在app.config文件中:
<configuration>
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>
<!-- Replace with your values -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Data Source=data.db3;Version=3</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver, NHibernate</property>
<property name="show_sql">true</property>
<property name="adonet.batch_size">0</property>
<property name="default_batch_fetch_size">0</property>
<mapping assembly="Infrastructure" />
</session-factory>
</hibernate-configuration>
</configuration>
在您的代码中:
var cfg = new Configuration().Configure();
var factory = cfg.BuildSessionFactory();