Ef6+mysql Code First

Source: Internet
Author: User
Tags mysql code mysql connect connectionstrings

1. Need to go to the official download MySQL connect/.net driver, address: Http://cdn.mysql.com//Downloads/Connector-Net/mysql-connector-net-6.9.9.msi

2. Create a simple project and refer to the file:

3. Enable Data migration: Enable-migrations-force

will prompt the error, you need to modify the configuration file, follow the steps to process

3.1 Comment out the default provider, if not, add it manually

<providers>
<provider invariantname= "MySql.Data.MySqlClient" type= "MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6 "/>
</providers>

3.2 Adding a connection string

<connectionStrings>
<add name= "Default" connectionstring= "SERVER=52.XXX.126;DATABASE=DB; Uid=root; pwd=xxx; "Providername=" MySql.Data.MySqlClient "/>
</connectionStrings>

4. Create a new entity class:

4. New DbContext (need to add a feature: [Dbconfigurationtype (typeof (MySql.Data.Entity.MySqlEFConfiguration))], otherwise the error:

After completing the above steps, when we run Add-migration adduser it is already possible to migrate successfully and then run Update-database. At this point the database will appear the entity we just added user

Ef6+mysql Code First

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.