使用NHibernate时出错

时间:2009-06-09 12:53:01

标签: asp.net nhibernate fluent-nhibernate nhibernate-mapping nhibernate.search

this example视为基本示例。我创建了应用程序,但是当我执行此应用程序时出现以下错误。

    The ProxyFactoryFactory was not configured.

使用一个可用的NHibernate.ByteCode提供程序初始化session-factory配置节的'proxyfactory.factory_class'属性。 例: 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 = "joe@cool.com";
        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();

    }
}

1 个答案:

答案 0 :(得分:2)

在构建工厂部分之前,可能缺少设置ProxyFactoryFactoryClass属性。

类似的东西:

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

不要忘记在项目中包含Linfu dll。

编辑:这是因为删除了对Castle的引用更新。您可以在此处获取更多信息:http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx