在Abp架構中使用Mysql資料庫的方法以及相關問題小記

來源:互聯網
上載者:User

標籤:csharp   log   mysql   var   provider   需要   ice   ide   cti   

最近發現了一款DDD的架構

 

看起來不錯,據說挺流弊的

 

剛好最近要弄點小東西,拿來試試也不錯

 

苦於窮逼買不起高配伺服器,只好裝mysql資料庫了

 

下面說下如何在該架構下使用Mysql資料庫

 

開啟項目後,在“封裝管理員控制平台”中選擇*.EntityFramwork以及*.Web項目(*號為你的項目名稱首碼)

 

Install-Package MySql.Data.Entity // Install-Package MySql.Data.Entity   - 安裝MySql.Data.Entity組件的命令

輸入以上語句安裝Mysql的相關組件

 

然後更改連接字串

<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" />//這裡可以看到以及自動為我們引用了mysql的相關項目      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer" />    </providers>  </entityFramework>  <connectionStrings><add name="Default" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=root" /></connectionStrings>

 

然後在“程式包管理控制平台”更新資料庫

 Update-Database –Verbose

至此,我們就可以使用該項目串連mysql資料庫了

 

實踐之中,經常會出現一些想不到的問題

 

這裡記下我自己遇到的幾個小問題

 

1、更新資料庫時提示“Specified key was too long; max key length is 767 bytes”

這個問題一般是由於(我認為,歡迎dalao指導)資料庫產生器配置不正確導致的,MSSql的相關配置在Mysql裡並不是全部適用

這時需要在Dbcontext類上指定產生器的類型

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]public class MyContext : DbContext{}

這裡的MyContext為你的EF相關類

 

2、忘了,想起來再寫吧

在Abp架構中使用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.