Fluent nhibernate 无法从Mono中的NHibernate.driver.MySqlDataDriver创建驱动程序
我创建了一个小应用程序,其中我使用的是Fluent Nhibernate。应用程序在windows上运行正常,但在Mono中出现异常Fluent nhibernate 无法从Mono中的NHibernate.driver.MySqlDataDriver创建驱动程序,fluent-nhibernate,mono,Fluent Nhibernate,Mono,我创建了一个小应用程序,其中我使用的是Fluent Nhibernate。应用程序在windows上运行正常,但在Mono中出现异常 ---> NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207
---> NHibernate.HibernateException: Could not create the driver from
NHibernate.Driver.MySqlDataDriver, NHibernate, Version=3.1.0.4000,
Culture=neutral, PublicKeyToken=aa95f207798dfdb4. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Configuration.ConfigurationErrorsException: Failed to find or
load the registered .Net Framework Data Provider
'MySql.Data.MySqlClient'.
at System.Data.Common.DbProviderFactories.GetFactory (System.String
providerInvariantName) [0x00000] in <filename unknown>:0
-->NHibernate.HibernateException:无法从创建驱动程序
NHibernate.Driver.MySqlDataDriver,NHibernate,版本=3.1.0.4000,
区域性=中性,PublicKeyToken=aa95f207798dfdb4。-->
System.Reflection.TargetInvocationException:已引发异常
通过调用的目标。-->
System.Configuration.ConfigurationErrorsException:找不到或
加载已注册的.Net Framework数据提供程序
“MySql.Data.MySqlClient”。
位于System.Data.Common.DbProviderFactorys.GetFactory(System.String
0中的providerInvariantName)[0x00000]
我用的是Kubuntu 11.10和Mono 2.10.5。Fluent NHibernate版本为1.2。Mono是否不完全支持Fluent NHibernate?根据我的经验,Fluent NHibernate在Mono上运行良好 事实上,我昨天才开始工作。不幸的是,我没有我的代码在我面前,但我会给你一些提示,直到我可以发布工作代码 我假设您已经下载了MySql.Data.dll,并在Mono项目中引用了它。需要注意的是,这个文件在下载后通常被称为MySQL.Data.dll。应该将其重命名为MySql.Data.dll(注意“Q”和“L”上的大小写更改) 然后,该库必须在GAC中注册才能使用Mono。简单地将文件放在相对路径中并引用它是不起作用的(我不完全确定为什么)。更多信息是 如果它仍然无法工作,您可能需要编写一个从NHibernate.driver.ReflectionBasedDriver派生的驱动程序。这是一段非常小的代码,我稍后会在有机会的时候发布 编辑:这是我正在使用的MySQL驱动程序
public class MySqlDriver : NHibernate.Driver.ReflectionBasedDriver
{
public MySqlDriver() : base(
"MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d",
"MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d",
"MySql.Data.MySqlClient.MySqlCommand, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
) { }
public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override string NamedPrefix
{
get { return "@"; }
}
public override bool SupportsMultipleOpenReaders
{
get { return false; }
}
}
…以及会话工厂功能
private string _ConnectionString = "";
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure().Database(
MySQLConfiguration.Standard.Driver<MySqlDriver>().ConnectionString(_ConnectionString)
).Mappings(
m => m.FluentMappings.AddFromAssemblyOf<YourType>()
).ExposeConfiguration(
BuildSchema
).BuildSessionFactory();
}
private void BuildSchema(Configuration config)
{
//new SchemaExport(config).Create(false, true);
new SchemaUpdate(config).Execute(false, true);
}
private string_ConnectionString=”“;
私有ISessionFactory CreateSessionFactory()
{
流畅地返回.Configure().Database(
MySQLConfiguration.Standard.Driver().ConnectionString(_ConnectionString)
).映射(
m=>m.FluentMappings.AddFromAssemblyOf()
).曝光配置(
构建模式
).BuildSessionFactory();
}
私有void BuildSchema(配置)
{
//新建SchemaExport(config).Create(false,true);
newschemaupdate(config).Execute(false,true);
}
我尝试在GAC中安装它,但它不起作用。我会试着把名字大写。这可能是Linux区分大小写的原因。谢谢老兄。有人认为,案件敏感性是问题的原因。我将文件名改为MySql.Data.dll,它可以正常工作。如果MySql.Data.dll在bin文件夹中进行应用,它也可以工作。谢谢@Sharique,我从MySql.Data.dll
通过MySql.Data.dll
和MySql.Data.dll
,直到你的MySql.Data.dll
最终工作。
private string _ConnectionString = "";
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure().Database(
MySQLConfiguration.Standard.Driver<MySqlDriver>().ConnectionString(_ConnectionString)
).Mappings(
m => m.FluentMappings.AddFromAssemblyOf<YourType>()
).ExposeConfiguration(
BuildSchema
).BuildSessionFactory();
}
private void BuildSchema(Configuration config)
{
//new SchemaExport(config).Create(false, true);
new SchemaUpdate(config).Execute(false, true);
}