没有为ADO.NET提供程序找到具有不变名称的实体框架提供程序' MySql.Data.MySqlClient'

时间:2015-02-20 18:33:23

标签: c# mysql entity-framework entity-framework-6 windows-forms-designer

指定的架构无效。错误:Model.ssdl(2,2):错误0152:找不到具有不变名称“MySql.Data.MySqlClient”的ADO.NET提供程序的实体框架提供程序。确保提供程序已在应用程序配置文件的“entityFramework”部分中注册。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882

尝试在Visual Studio 2013设计器中打开Form时出现此错误。 我在表单上有一个WindowsForms Usercontrol,我使用EF上下文访问数据库。有趣的是代码功能正常,但我无法访问表单设计器。

用户控制代码

namespace DipCom.UserControls
{
public partial class CasesControl : UserControl
{
    public vizualizaceEntities context;

    public CasesControl()
    {
        InitializeComponent();
        context = new vizualizaceEntities();
        restartListbox();
    }

    /// <summary>
    /// Method for filling case listbox
    /// </summary>
    public void restartListbox()
    {
        cases fil = new cases();
        listBoxCases.ValueMember = "name";
        listBoxCases.DataSource = context.cases.ToList();
    }

    /// <summary>
    /// Creates new case and add it to database.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void buttonNew_Click(object sender, EventArgs e)
    {
        if(textBoxName.ReadOnly==true)
        {
            clearTextBoxes();
            TBReadOnly(false); // readonly off
            EnableButtons(false, false, true, false);                  // others buttons off
        }
        else

        {
        cases newcase = new cases(textBoxName.Text, textBoxDescription.Text, textBoxReqNumber.Text); // crating new case 

        context.cases.Add(newcase);
        context.SaveChanges();
        // 
        EnableButtons(true,true,true,true);// enable all buttons
        TBReadOnly(true);
        clearTextBoxes();
        restartListbox();


        }
    }
    /// <summary>
    /// Enables or disables 3 textboxes in dependency on true/false par 
    /// </summary>
    /// <param name="par"></param>
    private void TBReadOnly(bool par) 
    {
        textBoxName.ReadOnly = par;
        textBoxReqNumber.ReadOnly = par;
        textBoxDescription.ReadOnly = par;  
    }
    /// <summary>
    /// Enables or disables buttons - each button has own bool parameter
    /// </summary>
    /// <param name="del"></param>
    /// <param name="change"></param>
    /// <param name="nevv"></param>
    /// <param name="chose"></param>
    private void EnableButtons(bool del, bool change, bool nevv, bool chose) {
        buttonDelete.Enabled = del;
        buttonChange.Enabled = change;
        buttonNew.Enabled = nevv;
        buttonChose.Enabled = chose;

    }

    /// <summary>
    /// Clear All textboxes
    /// </summary>
    private void clearTextBoxes()
    {


        textBoxDescription.Clear();
        textBoxName.Clear();
        textBoxReqNumber.Clear();


    }
    /// <summary>
    /// Changes properties of selected case.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void buttonChange_Click(object sender, EventArgs e)
    {
        if (textBoxName.ReadOnly == true)
        {
            TBReadOnly(false);
            EnableButtons(false, true, false, false);
        }
        else
        {

            cases selected = (cases)listBoxCases.SelectedItem;
            selected.changeCase(textBoxName.Text, textBoxDescription.Text, textBoxReqNumber.Text);
            context.SaveChanges();
            TBReadOnly(true);
            EnableButtons(true,true,true,true);
            restartListbox();
        }
    }

    private void listBoxCases_SelectedValueChanged(object sender, EventArgs e)
    {

        if (  listBoxCases.SelectedItem != null)
        {
            cases selected= (cases)listBoxCases.SelectedItem;
             textBoxName.Text = selected.name.ToString();
             textBoxReqNumber.Text = selected.reg_number.ToString();
             textBoxDescription.Text = selected.description.ToString();
        }
    }
    /// <summary>
    /// Deletes selected case
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void buttonDelete_Click(object sender, EventArgs e)
    {

        DialogResult dialogResult = MessageBox.Show("Jste si jistý, že chcete smazat případ?", "Smazat případ?", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.Yes)
        {
            cases selected = (cases)listBoxCases.SelectedItem;
            context.cases.Remove(selected);
            context.SaveChanges();
            restartListbox();
        }
        else if (dialogResult == DialogResult.No)
        {

          }

 }
 }
}

App.config文件如下。在我看来,问题可能在那里,但我不知道在哪里。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit     http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"      type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,    EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework     codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient"  type="MySql.Data.MySqlClient.MySqlProviderServices, 
    MySql.Data.Entity.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, 
    EntityFramework.SqlServer" />
  </providers>
  </entityFramework>
  <system.data>
  <DbProviderFactories>
  <remove invariant="MySql.Data.MySqlClient" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
   </DbProviderFactories>
   </system.data>
   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
      <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-6.9.5.0" newVersion="6.9.5.0" />
     </dependentAssembly>
      </assemblyBinding>
    </runtime>
    <connectionStrings>
   <add name="vizualizaceEntities" connectionString=""   providerName="System.Data.EntityClient"/>
    </connectionStrings>
   </configuration>

从Nuget导入包。

  • EntityFramework“version =”6.1.2“targetFramework =”net45“
  • MySql.Data“version =”6.9.5“targetFramework =”net45“
  • MySql.Data.Entities“version =”6.8.3.0“targetFramework =”net45
  • MySql.Data.Entity“version =”6.9.5“targetFramework =”net45“
  • MySql.Web“version =”6.9.5“targetFramework =”net45“

有人知道问题可能是什么?谢谢你的帮助。

0 个答案:

没有答案