无法将“Oracle.DataAccess.Client.OracleConnection”类型的对象强制转换为“System.Data.Common.DbConnection”类型

时间:2014-03-18 14:31:04

标签: c# oracle nhibernate

我试图第一次设置Nhibernate,我真的很挣扎!我正在使用Oracle数据库并具有以下内容

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="connection.driver_class">
        NHibernate.Driver.OracleDataClientDriver
      </property>
      <property name="connection.connection_string">
        Data Source=CTIR;Persist Security Info=True;User ID=****;Password=*****;
      </property>
      <property name="show_sql">
        true
      </property>
    </session-factory>
  </hibernate-configuration>
</configuration>

以下form1.cs:

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();
        SchemaMetadataUpdater.QuoteTableAndColumns(myConfig); <-- Here is the execption
        mySessionFactory = myConfig.BuildSessionFactory();
        mySession = mySessionFactory.OpenSession();

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

当我在调试模式下运行时,我收到以下错误:

Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.

谁能告诉我我做错了什么?

**更新**

根据这个问题:Stack question

我应该添加以下行:

 <property name="hbm2ddl.keywords">none</property>

然而,这并没有解决问题

0 个答案:

没有答案