我在Windows Server 2003中使用Visual Studio 2005和NHibernate-2.1.2.GA。
我尝试在我的ASP.net程序中将oracle与NHibernate连接。
要获取我的oracle版本,我运行此SQL:select * from v$version
结果显示oracle版本为oracle9i
。
所以,我这样写NHibernate.cfg.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=MYORACLE)));
user id=team;password=team;
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">10</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle
</property>
<mapping assembly="NHibernateSample.Domain"/>
</session-factory>
</hibernate-configuration>
现在,当我运行试图连接oracle并执行查询sql的测试单元时:
private ISession _session;
private SessionManager _helper;
private NHibernateSample _sample;
public void TestFixtureSetup()
{
_helper = new SessionManager();
}
public void Setup()
{
_session = _helper.GetSession();
_sample = new NHibernateSample(_session);
}
[NUnit.Framework.Test]
public void GetCustomerById1Test()
{
TestFixtureSetup();
Setup();
NHibernateSample _sample = new NHibernateSample(_session);
Assert.AreEqual(1, _sample.GetCustomerById(1).Id);
}
它会报告如下错误:
Test 'NHibernateSample.Data.Test.NHibernateSampleFixture.GetCustomerById1Test' failed: NHibernate.MappingException : Could not compile the mapping document: NHibernateSample.Domain.Mappings.Customer.hbm.xml
----> NHibernate.HibernateException : Could not instantiate dialect class NHibernate.Dialect.Oracle9iDialect
----> System.TypeLoadException : Could not load type org.NHibernate.Dialect.Oracle9iDialect. Possible cause: no assembly name specified.
我知道这是初学者的问题,但我只是个新手!我很感激你的想法...
答案 0 :(得分:2)
再次尝试从org.
dialect
<property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
从官方文档中查看NHibernate SQL Dialects以获取更多详细信息。
答案 1 :(得分:0)
感谢上帝,最后我解决了这个问题。 Thers是结果中的一条消息,我忘记粘贴在上面,就像这样:
未能从程序集“mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.DateTimeOffset”
这是因为我的.Net2.0版本已经过时了。 然后我安装.Net2.0 SP1并修复了probelm! 谢谢Claudio Redi一样!