我使用Devart Postgres的驅動程序與NHibernate的Ado.net提供商。由於NHibernate不支持Devart Postgres驅動程序,我寫了一個基於ReflectionBasedDriver的自定義驅動程序類。下面是代碼:無法加載自定義ADO.NET提供了NHibernate的
namespace PostgresDriver.DbDriver
{
class DevartPgDriver : ReflectionBasedDriver
{
public DevartPgDriver()
: base(
"Devart.Data.PostgreSql",
"Devart.Data.PostgreSql.PgSqlConnection",
"Devart.Data.PostgreSql.PgSqlCommand")
{
}
public override string NamedPrefix
{
get { return ":"; }
}
public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override bool SupportsMultipleOpenReaders
{
get { return false; }
}
protected override bool SupportsPreparingCommands
{
get { return true; }
}
public override IResultSetsCommand GetResultSetsCommand(NHibernate.Engine.ISessionImplementor session)
{
return new BasicResultSetsCommand(session);
}
public override bool SupportsMultipleQueries
{
get { return true; }
}
protected override void InitializeParameter(IDbDataParameter dbParam, string name, NHibernate.SqlTypes.SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
// Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL instead of its native 2 decimal currency type.
if (sqlType.DbType == DbType.Currency)
dbParam.DbType = DbType.Decimal;
}
}
}
我已經加入Devart.Data和Devart.Data.PostgreSql DLL文件在我的解決方案,並設置「複製本地」屬性設置爲True引用。我還添加了App.Config中的以下部分:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Devart.Data.PostgreSql"
fullName="Devart.Data.PostgreSql, Version=7.2.80.0, Culture=neutral, PublicKeyToken=09af7300eec23701">
</qualifyAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Devart.Data"
fullName="Devart.Data, Version=5.0.872.0, Culture=neutral, PublicKeyToken=09af7300eec23701">
</qualifyAssembly>
</assemblyBinding>
</runtime>
這裏是我的hibernate.cfg.xml:
<session-factory name="NHSessionFactory">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">PostgresDriver.DbDriver.DevartPgDriver, Devart.Data.PostgreSql</property>
<property name="dialect">NHibernate.Dialect.PostgreSQL82Dialect</property>
<property name="connection.connection_string">User Id=***;Password=***;Host=localhost;Port=5433;Database=***;</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property
</session-factory>
當我打電話sessionFactory = cfg.BuildSessionFactory();
我得到以下錯誤:"Could not load type 'PostgresDriver.DbDriver.DevartPgDriver' from assembly 'Devart.Data.PostgreSql, Version=7.2.80.0, Culture=neutral, PublicKeyToken=09af7300eec23701'."
當我嘗試實例化驅動程序類DevartPgDriver dr = new DevartPgDriver();
時,我得到靜態成員下的錯誤:
NHibernate.Driver.ReflectionBasedDriver.ReflectionTypedProviderExceptionMessageTemplate
"The IDbCommand and IDbConnection implementation in the assembly {0} could not be found. Ensure that the assembly {0} is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly."
我錯過了什麼?我已經解決了這個問題幾個小時沒有太多成功。請幫忙!
它不是' PostgresDriver.DbDriver.DevartPgDriver,Devart.Data '你的類是什麼組合?PostgresDriver.DbDriver.DevartPgDriver? –
Rippo
它在PostgresDriver程序集中。 – aparajithanv
您的自定義類是'PostgresDriver.DbDriver.DevartPgDriver'名爲'PostgresDriver'的組件(請注意,我說你的自定義類?) – Rippo