This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27893|Reply: 2

[Source] EF(CodeFirst) + MySQL

[Copy link]
Posted on 2020-7-3 14:30:39 | | | |
This post was last edited by QWERTYU on 2020-7-3 14:43

Prerequisites:

PreparationsDownload address
mysql-installer-community-8.0.18 The hyperlink login is visible.
MySQL for Visual Studio 1.2.7 The hyperlink login is visible.
mysql-connector-net-6.10.7.0 The hyperlink login is visible.


Steps:
1: AddADO.NET Entity Data Model, select CodeFirst Model.

2: AddMySql.Data.Entity (note that the version should be the same as the one installed in the machine).

3: Add modify the connection string, (If it is a newly created class library, you should manually add the connection string in the application configuration file. )

4: Add a test user class.


5: OpenNuGet package management console and select the corresponding project. Execute enable-migrationscommand, which generates a folder with the version numberMigrations

6: In the generated Migrations folder, add SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

7: Executionadd-migrationcommand, enter the name of a version number. (This step is required every time the model is modified in the future.)

8: Executionupdate-databasecommandUpdate-Database -Verbose Add one-Verboses to view the generated SQL statementsAfter executing this command, the database will be generated (this step will be required every time the model is modified in the future).


Error Problem Resolution:
1: Execute Enable-Migrations, error is reported:The type of member "System.Data.Entity.Migrations.Design.ToolingFacade+GetContextTypeRunner,EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" is not resolved.
Solution: Look at the class libraries and applications usedWhether the EntityFramework version is consistent, my library is 6.2.0, the application is 6.1.3, change the application to 6.2.0, and the error is not reported when executed again.

2: ExecutionAdd-Migration, error:No MigrationSqlGenerator was found for the provider "MySql.Data.MySqlClient". Use the SetSqlGenerator method in the target migration configuration class to register additional SQL generators.
Solution:Add in the constructorSetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());






Previous:. .NET project renaming in detail
Next:.Net/C# Selenium automated tests get cookie values
Posted on 2020-7-4 00:20:47 |
Very good, I studied, thank you landlord."
Posted on 2020-7-4 22:40:25 |
Thanks for sharing!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com