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