Ef+mvc+mysql

Source: Internet
Author: User
Tags mysql for visual studio connectionstrings

This is a really big hole. TM Toss an afternoon finally got it. Quickly record and share to everyone, lest have and I have been configured not successful and toss half a day ....
1. Installing MySQL for Visual Studio
This will be downloaded and installed directly on the MySQL website.
But this must be vs2013 Professional version above can!!
2. Install MySQL Connector/net
This can be obtained through the NuGet tool, more relaxed and enjoyable, of course, you can also download yourself, quote yourself.
3. Configure Web. config.
The first is the connectionstrings node

1<connectionStrings>2<add name="defaultconnection"connectionstring="Data source= (LocalDb) \v11.0;initial catalog=aspnet-mymvc-20150122222755;integrated Security=sspi; attachdbfilename=| Datadirectory|\aspnet-mymvc-20150122222755.mdf"Providername="System.Data.SqlClient"/>3<add name="Moviedbcontext"Providername="MySql.Data.MySqlClient"connectionstring="Server=localhost;4port=3306;d atabase=mymvc;uid=root;password="/>5</connectionStrings>


Then the System.Data node and the system.web node
System.Web Add the following code

1<rolemanager enabled="true"Defaultprovider="Mysqlroleprovider">2<providers>3<clear/>4<add name="Mysqlroleprovider"Autogenerateschema="true"5Type="MySql.Web.Security.MySQLRoleProvider, Mysql.web, version=6.8.4.0,6Culture=neutral, publickeytoken=c5687fc88969c44d"7Connectionstringname="Mariodb"Applicationname="/"/>8</providers>9</roleManager>Ten      One<membership defaultprovider="Mysqlmembershipprovider"> A<providers> -<clear/> -<add name="Mysqlmembershipprovider"Autogenerateschema="true" theType="MySql.Web.Security.MySQLMembershipProvider, Mysql.web, -version=6.7.4.0, Culture=neutral, publickeytoken=c5687fc88969c44d" -Connectionstringname="Mariodb"Enablepasswordretrieval="false" -enablepasswordreset="true"Requiresquestionandanswer="false" +Requiresuniqueemail="true"maxinvalidpasswordattempts="5" -Minrequiredpasswordlength="6"minrequirednonalphanumericcharacters="0" +passwordattemptwindow="Ten"Applicationname="/"/> A</providers> at</membership>


System.Data node

1<system.data>2<DbProviderFactories>3<remove invariant="MySql.Data.MySqlClient"/>4<add name="MySQL Data Provider"Invariant="MySql.Data.MySqlClient"5description=". Net Framework Data Provider for MySQL"6Type="Mysql.data.mysqlclient.mysqlclientfactory,mysql.data"/>7</DbProviderFactories>8</system.data>


Notice that the above version=6.8.4.0 is changed to your version number.
4. Implement the default constructor for DbContext in your module class, as below my

1    usingSystem;2    usingSystem.Data.Entity;3    usingMysql.data;4    usingMySql.Data.Entity;5    usingMySql.Web.Security;6    namespaceMymvc.models7    {8         Public classMovie9        {Ten             Public intID {Get;Set; } One             Public stringTitle {Get;Set; } A             PublicDateTime ReleaseDate {Get;Set; } -             Public stringGenre {Get;Set; } -             Public decimalPrice {Get;Set; } the        } -      -      -           +         Public classMoviedbcontext:dbcontext -        { +             PublicMoviedbcontext ():Base("Moviedb") { } A             PublicDbset<models.movie> Moves {Get;Set; } at        } -}


5. Add Mysql.data and Mysql.web to the reference.

Ef+mvc+mysql

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.