Error using NHibernate

蓝咒 提交于 2020-01-24 17:47:07

问题


Considering this example as a base example. I created the application but when I execute this application getting the following error.

    The ProxyFactoryFactory was not configured.

Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Following is the code snippet i am using.

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:


Maybe you are missing to set the ProxyFactoryFactoryClass property before building you section factory.

Something like:

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

Don't forget to include the Linfu dll in your project.

EDIT: this happens due to an update to reference to Castle removed. You may obtain more information here: http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx



来源:https://stackoverflow.com/questions/969894/error-using-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!