【问题标题】:nhibernate web.config issuesnhibernate web.config 问题
【发布时间】:2011-08-04 01:38:30
【问题描述】:

我正在设置一个休眠项目,但我不断收到代理错误。我已经将 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。使用可用的 >NHibernate.ByteCode 提供程序之一初始化会话工厂配置部分的“proxyfactory.factory_class”属性。示例:NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu 示例:NHibernate.ByteCode.Castle.ProxyFactoryFactory,>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();

请帮忙...

【问题讨论】:

  • 将代码的每一行缩进 4 个空格以使其正确显示。您还需要格式化您发布的 web.config 文件,使其可读。你应该能够找到如何做到这一点here。像现在这样很难阅读。

标签: .net nhibernate


【解决方案1】:

您还需要在项目中添加对代理提供程序的引用(Project > Add Reference... 并选择 NHibernate.ByteCode.Castle.dll)。

【讨论】:

  • @James,您确认 NHibernate.ByteCode.Castle.dll 正在被复制到您的部署文件夹吗?
【解决方案2】:

在添加程序集之前,您错过了对 config.Configure() 的调用。

【讨论】:

  • +1。 《NHibernate in Action》一书在代码示例中留下了同样的内容,它让我想找出问题所在。
猜你喜欢
  • 2011-07-22
  • 2016-08-11
  • 2014-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 1970-01-01
相关资源
最近更新 更多