2

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

    The ProxyFactoryFactory was not configured.

使用可用的 NHibernate.ByteCode 提供程序之一初始化会话工厂配置部分的“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();

    }
}
4

1 回答 1

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

于 2009-06-09T13:13:02.090 回答