2

考慮this example作爲基礎示例。我創建了應用程序,但是當我執行此應用程序時出現以下錯誤。使用NHibernate時出錯

The ProxyFactoryFactory was not configured. 

初始化「proxyfactory.factory_class」與可用NHibernate.ByteCode提供商之一會話工廠配置部分的屬性。 實施例: NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu 示例: NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle

以下是代碼片段我使用。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using NHibernate; 
using NHibernate.Cfg; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     Configuration cfg = new Configuration(); 
     cfg.AddAssembly("NHibernate"); 


     ISessionFactory factory = cfg.BuildSessionFactory(); //getting error at this line 
     ISession session = factory.OpenSession(); 
     ITransaction transaction = session.BeginTransaction(); 
     User newUser = new User(); 
     newUser.Id = "joe_cool"; 
     newUser.UserName = "Joseph Cool"; 
     newUser.Password = "abc123"; 
     newUser.EmailAddress = "[email protected]"; 
     newUser.LastLogon = DateTime.Now; 

     // Tell NHibernate that this object should be saved 
     session.Save(newUser); 

     // commit all of the changes to the DB and close the ISession 
     transaction.Commit(); 
     session.Close(); 

    } 
} 
+0

你的配置是什麼樣的? – 2009-06-09 13:02:32

+0

確定我的配置樣子 ?XML版本= 「1.0」 編碼= 「UTF-8」?> <結構> <節 名稱= 「NHibernate的」 類型=「System.Configuration.NameValueSectionHandler,系統,版本= 1.0.5000.0文化=中性公鑰= b77a5c561934e089" /> 2009-06-09 13:18:45

回答

2

也許你缺少設置ProxyFactoryFactoryClass屬性之前,建立你的部門工廠。

喜歡的東西:

Config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Linfu.ProxyProxyFactory, NHibernate.Bytecode.Linfu"); 

不要忘記在項目中包含的李林甫DLL。

編輯:這是由於更新引用城堡刪除。您可以在這裏獲得更多信息:http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx