Entity framework database first 使用MySQL
前言
本篇提供使用Entity framework,資料來源為MySQL的使用者參考。
測試環境:
Visual studio 2015 community
MySQL 5.6.25-log
目錄
1.Insatll Download MySQL for Visual Studio
2.Install Download Connector/Net
3.Setting on Visual studio
重要:一定要先安裝Download MySQL for Visual Studio,再安裝Download Connector/Net
Impotrtant: Always install the MySQL for Visual Studio before installing MySQL Connector/Net.
Insatll Download MySQL for Visual Studio
下載 MySQL Installer,選擇安裝 MySQL for Visual Studio
或
直接下載 MySQL for Visual Studio
You can download MySQL Installer, select and install MySQL for Visual Studio
or
directly download and install MySQL for Visual Studio
Step.1 開啟 MySQL Installer ,進行下載安裝程式。
Open MySQL Installer and download installer
Step.2 點選安裝程式進行安裝
Click Installer and install
Step.4 關閉相關程式
Close related application
Step.6 選擇MySQL for Visual 1.2.6 後點下一步,點選執行
Select MySQL for Visual 1.2.6, Click Next, then click excute
完成後,接下來要安裝Connector/Net
After installing MySQL for Visual Studio, We need to install Connector/Net
Install Download Connector/Net
Step.2 點選安裝程式進行安裝
Click Installer and install
Step.5 點選Typical
Click Typical
Step.6 點選Install
Click Install
Step.7 選擇Visual Studio 2015
Select Visual Studio 2015
Setting on Visual studio
Open Visual Studio 2015, Select File -> New -> Project
Step 2.選擇 ASP.NET Web Application, 輸入專案名稱
Select ASP.NET Web Application, Enter name: MySQLTest
Step 4.右鍵點選References -> Add reference
Right Click References -> Add reference
Step 6. 開啟Web.config, 找到
Open Web.config, find
Step 6. 瀏覽並加入下列 dll
browse and add following dll:
MySql.Data.dll
MySql.Data.Entity.EF6.dll
MySql.Web.dll
位置(Path):
C:\Program Files\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (32bit windows)
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (64bit windows)
Step 7. 點選 View -> Sever Explorer, 右鍵點選 Data connections, 點選Add connection..
Click View -> Sever Explorer, right click Data connections, Click Add connection..
Step 8. 點選Change...
Click Change...
Step 9. 選擇 MySQL Database, 點選OK
Select MySQL Database, Click OK
Step 10. 輸入Sever name, User name ,Password, and database name.
Enter Sever name, User name ,Password, and database name
Step 11. 右鍵點選Model 資料夾 -> Add -> New Item
Right click Model folder -> Add -> New Item
Step 12. 選擇 Data -> ADO.NET Entity Data Model, 點選 add
Select Data -> ADO.NET Entity Data Model, Click add
Step 13. 選擇 EF Desginer from database, 點選Next...
Select EF Desginer from database, Click Next...
Step 14. 選擇connection, 點選 Next...
Select conntecion, Click Next....
Step 15. 選擇需要載入的table, 點選 Finish.
Check tabkes, click Finish.
完成Model載入後,即可以開始進行開發。
參考資料
https://dev.mysql.com/doc/visual-studio/en/visual-studio-install.html
http://qursaan-howto.blogspot.tw/2014/07/solve-your-project-references-latest.html
上一篇:Entity framework database first with localdb
下一篇:Entity framework code first with localdb
本篇文章內容歡迎分享,轉載與使用圖文請來信告知並註明出處。