Entity Framework Code First ---EF Power Tool MySql

來源:互聯網
上載者:User

標籤:mysql   ros   ram   encoding   div   img   local   --   param   

關於如何使用EF Power Tool的介紹請看 http://www.cnblogs.com/LingzhiSun/archive/2011/05/24/EFPowerTool_1.html, 這裡不再囉嗦。

MySql裡有個預設的範例資料庫 world, 裡面有三個表,

下載Entity Framework Power Tools 安裝包, 現在已經是Beta3版本,http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/

下載完安裝, 然後建立一個控制台項目,項目名稱為EFEntity, 然後右鍵點擊項目名,在快顯功能表中選擇Entity Framework –》Reverse Engineering Code First 。

 

選擇相應的資料庫連接

 

可以看到引用了不該引用程式集

App.Config 也多了一個Providers子節點

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>   
//把這個子節點刪除
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

 

需要把Providers子節點整個刪掉,引用Mysql Connector的驅動,才能正常運行程式。

另外,Power Tool 安裝的EF 預設版本是6.6.0.0, 這個版本在VS2012環境下可以正常工作, 在VS2010 .NET 4.0 的環境下不行,要用NuGet卸載掉,然後重新安裝,之後看到的版本是4.4.0.0.

 

Program.cs的代碼是:

   1:      class Program
   2:      {
   3:          static void Main(string[] args)
   4:          {
   5:              using (var context = new worldContext())
   6:              {
   7:                  foreach (var item in context.cities)
   8:                  {
   9:                      Console.WriteLine(item.Name + "  " + item.District + "  " + item.CountryCode);
  10:                  }
  11:                  Console.Read();
  12:              }
  13:          }
  14:      }
 
 

App.Config檔案內容:

<?xml version="1.0" encoding="utf-8"?><configuration>  <configSections>    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  </configSections>  <connectionStrings>    <add name="worldContext" connectionString="server=localhost;Character Set=utf8;User Id=root;password=pristine2008;Persist Security Info=True;database=world" providerName="MySql.Data.MySqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework></configuration>

Entity Framework Code First ---EF Power Tool MySql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.