【NHibernate】列「ReservedWord」不屬於表 ReservedWords

NHibernate+FluentNHibernate+MySql

運行時黃頁顯示下邊的異常,項目中找了半天沒出現過這個列的關鍵字。sql

[ArgumentException: 列「ReservedWord」不屬於表 ReservedWords。]
   System.Data.DataRow.GetDataColumn(String columnName) +5310119
   System.Data.DataRow.get_Item(String columnName) +13
   NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords() +170
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) +100
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) +78
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +700
   NHibernate.Cfg.Configuration.BuildSessionFactory() +104
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in c:\work\coding\fluentNhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:230

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.]

  

百度到下邊的相似問題:session

error1.  Could not create the driver from NHibernate.Driver.MySqlDataDriverapp

解決方法:在使用Nhibernate鏈接Mysql時報這個錯, 請把MySql.Data.dll文件手動 拷貝到xxx/工程文件目錄/bin/Debug下 就能夠解決這個問題了!
 
error2. 列「ReservedWord」不屬於表 ReservedWords
解決方法:在 hibernate.cfg.xml配置文件中加入 <property name="hbm2ddl.keywords">none</property>
 
 
最後在stackoverflow上找到對應的用 FluentNHibernate配置的方法(最後一行的配置):
Configuration.DefaultNameOrConnectionString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
Configuration.Modules.AbpNHibernate().FluentConfiguration
             .Database(MySQLConfiguration.Standard.ConnectionString(Configuration.DefaultNameOrConnectionString))
             .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));
             .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none"));

 

問題解決,主要對NHibernate和FluentNHibernate都不太熟悉,記錄一下。ui

相關文章
相關標籤/搜索