標籤: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資料庫的方法以及相關問題小記