EF6 Codefirst+mysql Database Migration

Source: Internet
Author: User
Tags mysql for visual studio

      • Brief introduction
        • The project uses MSSQL as a database, but because the SQL Server is a bit more expensive and the concurrency connection is a little bit worse, migrating data to MySQL, incidentally, and the problem.
      • Environment
        • Visual Studio 2013
        • MySQL 5.7
        • Entity Framework 6.1.3
      • Body
        • Migration process
          1. Install MySQL, incidentally install MySQL for Visual Studio, MySQL Connector Net
          2. Add a NuGet package to the Entity Framework Project and the website project. MySql.Data.Entity, I added here is the 6.9.6 version, add the Mysql.data as a dependency after adding to the project, you can see that after completing the Web. config and app. Config added MySQL Provider and Dbprovidefactories.

          3. Modify the connection string for Web. config, providername modified to: MySql.Data.MySqlClient.
          4. Back in the EntityFramework project, locate the DbContext class and add properties for the class: [Dbconfigurationtype (typeof (MySql.Data.Entity.MySqlEFConfiguration))]
          5. OK, these jobs are done, basically, open the Package Manager console, pray, and then enter: Update-database
      • Migration issues
        1. Object references are not set to an instance of an object.
          • Problem Description: This is a more general error hint, many errors will prompt this, the Internet to find some less right, the final discovery is because the startup item is set to the EF project, and the default project is also the EF project, because the config file is not caused by the connection string.
          • Solution: Add a connection string to the Ef App. Config, or the startup project is set to website.
        2. Underlying provider does not support the type ' nvarchar (max) '.
          • Problem Description: Literally means that provider does not support type "nvarchar (max)", which is related to the data types supported by the MySQL database.
          • Solution: Find out if the entity definition has a String type, add properties such as: [Stringlength (1000)], and then solve the problem.

EF6 Codefirst+mysql Database Migration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.