找不到C#Nhibernate ConnectionProvider.cs

时间:2014-03-18 13:44:03

标签: c# nhibernate

到目前为止,我尝试使用oracle数据库设置Nhibernate,我有以下内容:

App.config(香港专业教育学院注释掉了用于保护的用户名和密码)

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
      <property name="query.substitutions">hqlFunction=SQLFUNC</property>
      <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
      <property name="connection.connection_string">Data Source=CTIR;Persist Security Info=True;User ID=****;Password=****;Unicode=True</property>
      <property name="show_sql">true</property>
      <mapping assembly="TestNhibernate" />
    </session-factory>
  </hibernate-configuration>
</configuration>

Agenter.cs

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestNhibernate
{
    class Agenter
    {
        public virtual int ID {get; set;}
        public virtual String Initialer { get; set; }
        public virtual String Fornavn { get; set; }
        public virtual String efternavn { get; set; }

    }
}

AGENTER_LISTE.hbm.xml

    <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestNhibernate" namespace="TestNhibernate">
  <class name="Agenter">
    <id name="ID" column="ID">
      <generator class="identity" />
    </id>
    <property name="Initialer" />
    <property name="Fornavn" />
    <property name="Efternavn" />
  </class>
</hibernate-mapping>

Form1.cs中:

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NHibernate.Cfg;
using NHibernate;

namespace TestNhibernate
{

    public partial class Form1 : Form
    {
        private Configuration myConfig;
        private ISessionFactory mySessionFactory;
        private ISession mySession;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            myConfig = new Configuration();
            myConfig.Configure();
            mySessionFactory = myConfig.BuildSessionFactory(); <--- this is where it goes wrong
            mySession = mySessionFactory.OpenSession();

            using (mySession.BeginTransaction())
            {
                Agenter agent = new Agenter {Fornavn = "Marc", Initialer = "MRCR212", ID = 999, efternavn = "Rasmussen" };
                mySession.Save(agent);
                mySession.Transaction.Commit();
            }
        }
    }
}

我收到以下错误:

Could not create the driver from NHibernate.Driver.OracleDataClientDriver.

我缺少什么?

3 个答案:

答案 0 :(得分:1)

确保 Oracle.DataAccess.dll 位于GAC或bin文件夹中。

答案 1 :(得分:1)

Oracle现在允许进行XCopy部署。

但你必须做一些腿部工作。

http://dbaportal.eu/2013/02/22/true-xcopy-runtime-for-oracle-odp-net-application/

答案 2 :(得分:1)

Oracle发布托管驱动程序并且它们与nhibernate一起使用我会使用它们而不是Oracle.DataAccess.dll。它们的大小要小得多,而且二进制文件可以是任何cpu