本文介绍了使BLToolkit与MySQL一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heya,我目前正在尝试让bltoolkit在我的项目中正常工作.我已经将BLToolkit.3项目添加到我的解决方案中,并且正在对其进行适当的引用.

Heya, I'm currently trying to get bltoolkit working in my project.I've added the BLToolkit.3 project to my solution and am referencing it appropriately.

有问题的代码非常简单.

The code in question is really simple.

    public List<Account> LoadAccounts()
    {
        using (DbManager db = new DbManager("MySql"))
        {
            var query = new SqlQuery<Account>();
            return query.SelectAll(db);
        }
    }

的app.config为

With an app.config of

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="bltoolkit" type="BLToolkit.Configuration.BLToolkitSection, BLToolkit.3"/>
  </configSections>

  <bltoolkit>
    <dataProviders>
      <add type="BLToolkit.Data.DataProvider.MySqlDataProvider" />
    </dataProviders>
  </bltoolkit>

  <connectionStrings>
    <add name="MySql" connectionString="Server=localhost;Port=3306;Database=BLT;Uid=root;" providerName="MySql.Data.MySqlClient"/>
  </connectionStrings>
</configuration>

当我尝试运行该代码时,出现以下异常:'BLToolkit.Data.DbManager'的类型初始化程序引发了异常."

When I try to run that, I get the following exception: "The type initializer for 'BLToolkit.Data.DbManager' threw an exception."

仔细检查,似乎在DbManager.Config.cs中是第261行

Upon closer inspection it seems to be line 261 in DbManager.Config.cs

Type             dataProviderType = Type.GetType(provider.TypeName, true);

基本上无法获取MySQL提供程序类型.我尝试将MySQL.data.dll放入我的应用程序的运行路径中,但是没有运气.

Which basically fails to get the MySQL providers type. I've tried putting the MySQL.data.dll in my applications run path, with no luck.

有什么想法吗?

推荐答案

默认情况下,MySqlDataProvider不包含在构建中.您将必须下载源代码并将MySqlDataProvider.cs作为现有项目"添加到项目中(并适当地修改程序集限定的类型名称).或者,如果您适合重新编译BLTooklit,则可以将其包含在BLToolkit项目本身中.

By default, MySqlDataProvider is not included in build. You'll have to download source code and add MySqlDataProvider.cs as "Existing Item" to your project (and modify assembly-qualified type name appropriately). Or, if you're fine with recompiling BLTooklit, you can include it in BLToolkit project itself.

这篇关于使BLToolkit与MySQL一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 19:12