【发布时间】:2009-06-05 14:47:29
【问题描述】:
我是新的 NHibernate。我正在编写一个简单的应用程序,它的客户类包含 id 和 name,并使用 nhibernate 我将对象存储到数据库。 但我得到以下内容
未配置 ProxyFactoryFactory。
使用可用的 NHibernate.ByteCode 提供程序之一初始化会话工厂配置部分的“proxyfactory.factory_class”属性。
示例:<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> 示例:<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
阅读此错误后,我在我的应用程序中添加了参考 NHibernate.ByteCode.Castle。我仍然收到错误。我在 cfg.xml 文件中声明
hibernate.cfg.xml 文件
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=(local);Initial Catalog=Customer;User Id=sa;Password=myPassword1</property>
</session-factory>
</hibernate-configuration>
客户.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ConsoleApplication1" assembly="ConsoleApplication1">
<class name="ConsoleApplication1.Customer" table="Customer">
<id name="Id" type="string" length="40">
<generator class="assigned"></generator>
</id>
<property name="Name" column="Name" type="String" length="40"></property>
</class>
</hibernate-mapping>
主要功能
Configuration cfg = new Configuration();
cfg.AddAssembly(Assembly.GetCallingAssembly());
ISessionFactory factoty = cfg.BuildSessionFactory();
ISession session = factoty.OpenSession();
ITransaction TRANS = session.BeginTransaction();
Customer newCustomer = new Customer();
newCustomer.ID = "1";
newCustomer.Name = "test";
session.Save(newCustomer);
session.Close();
谁能帮助我? 提前致谢
【问题讨论】:
-
您还需要对 Castle.Core.dll 和 Castle.DynamicProxy2.dll 的引用
-
我添加了两个 dll 但仍然出现同样的错误。
标签: nhibernate