2015-04-29 16 views
2

編輯:發現這個職位和這個工作,但不得不從贏形式運行:試圖從數據庫中首先獲得MySQL的代碼工作

Enable Entity Framework 6 for MySql (C#) in WinForms of Microsoft Visual Studio 2013

OP ------- -------------

我創建了一個控制檯C#應用程序

  • 當我右鍵單擊我的凸出ECT,
  • 轉到添加新的項目,
  • 我添加ADO.Net實體數據模型稱爲模型1
  • 然後我選擇MySQL連接和命中完成

什麼也沒有發生。它只關閉嚮導,什麼都不做。

任何人都遇到過這個問題?

我已經安裝了MySQL的VISAUL工作室計劃,並同時運行此命令NPM:

Install-Package Mysql.Data.Entities 

我的App.config看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <entityFramework> 
    <providers> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> 
    </providers> 
    </entityFramework> 
    <system.data> 
    <DbProviderFactories> 
     <remove invariant="MySql.Data.MySqlClient"></remove> 
     <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.8.3.0" /> 
    </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.8.5.0" newVersion="6.8.5.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 
+0

檢查在事件查看器,看看是否有相關的錯誤日誌或警告。 (移動回答評論) – AndroidMechanic

回答

0

需要爲了一個連接字符串連接到數據庫。你沒有那個信息。

假設你安裝Mysql.Data好,試試這個代碼:

MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder(); 
conn_string.Server = "yourserver.com"; 
conn_string.UserID = "youruser"; 
conn_string.Password = "yourpass"; 
conn_string.Database = "yourdatabasename"; 

using (MySqlConnection conn = new MySqlConnection(conn_string.ToString())) 
using (MySqlCommand cmd = conn.CreateCommand()) 
{ //watch out for this SQL injection vulnerability below 
    cmd.CommandText = string.Format("SELECT * FROM Users --Just to test"); 
    connection.Open(); 
    cmd.ExecuteNonQuery(); 
} 
+0

我將所有細節輸入到ADO net嚮導中,但未能從數據庫中開始構建模型。這可能不是嘗試自己構建模型及其依賴關係的最佳方法,最好讓EF做到這一點...... – Jimmyt1988

相關問題