- using FluentNHibernate.Cfg;
- using NHibernate;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using FluentNHibernate.Cfg.Db;
-
- namespace TaidouDatabase
- {
- class NHibernateHelper
- {
- private static ISessionFactory sessionFactory = null;
-
- private static void InitializeSessionFactory()
- {
- sessionFactory = Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(
- db => db.Server("localhost").Database("taidou").Username("root").Password("root"))).Mappings(x => x.FluentMappings.AddFromAssemblyOf<NHibernateHelper>()).BuildSessionFactory();
- }
- private static ISessionFactory SessionFactory
- {
- get
- {
- if (sessionFactory == null)
- InitializeSessionFactory();
- return sessionFactory;
- }
- }
-
- public static ISession OpenSession()
- {
- return SessionFactory.OpenSession();
- }
- }
- }
错误提示:“FluentNHibernate.Cfg.FluentConfigurationException”类型的未经处理的异常在 FluentNHibernate.dll 中发生
其他信息: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
解决方法:将数据库MySQL.Data.dll文件手动拷贝到工程文件目录/bin/Debug目录上,就可连接上数据库。成功解决该问题
百度到其他一些问题及解决方案解决方案:
Error: 列“ReservedWord”不属于表 ReservedWords
解决方法:在hibernate.cfg.xml配置文件中加入<property name="hbm2ddl.keywords">none</property>