我正在设置一个hibernate项目,并且我一直在收到代理错误。我已经将Castle引用添加到了我的项目中。我的web.config有以下内容:
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=192.168.1.100, 0000;Initial Catalog=GDER;Persist Security Info=True;User ID=re;Password=none12</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</nhibernate>
然而,我始终得到以下错误
未配置ProxyFactoryFactory。使用一个可用的&gt; NHibernate.ByteCode提供程序初始化会话工厂配置部分的'proxyfactory.factory_class'属性。示例:NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu示例:NHibernate.ByteCode.Castle.ProxyFactoryFactory,&gt; NHibernate.ByteCode.Castle
此处的调试始终失败(NHibernate.ISessionFactory factory = config.BuildSessionFactory();
):
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
// add our assembly
config.AddAssembly("nHibernateTest");
// setup nhibernate session
NHibernate.ISessionFactory factory = config.BuildSessionFactory();
NHibernate.ISession session = factory.OpenSession();
// start nhibernate transaction
NHibernate.ITransaction transaction = session.BeginTransaction();
请帮忙......
答案 0 :(得分:1)
您还需要在项目中添加对代理提供程序的引用(Project&gt; Add Reference ...并选择NHibernate.ByteCode.Castle.dll)。
答案 1 :(得分:1)
在添加程序集之前,您错过了对config.Configure()
的调用。