The Entity framework connects to the MySQL database and generates the model and DAL layers

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

The Entity Framework (Ef,ado.net Entity Framework) is officially provided by Microsoft. NET platform's ORM framework. There is a clear advantage over the LINQ to SQL,EF framework:

    • The EF framework supports a variety of databases, not just Microsoft's SQL Server,mysql,oracle.

    • Supports stored procedures.

    • Powerful visual model design tool for deep integration with Visual Studio.

    • Integrates well with other technologies in the. NET platform.

There are many online tutorials on using entityframe to connect MySQL database, but many of them are not reliable, reproduced too much. Looked for a long time, finally is configured, now share.

Next we'll show you how to access the MySQL database using the EF framework.

One, Installation: 1, development environment: VS2013 and EF62, MySQL database: MySQL Server 6.03, installation: MySQL for Visual Studio 1.1.1 Download location: https://cdn.mysql.com/ DOWNLOADS/MYSQLINSTALLER/MYSQL-VISUALSTUDIO-PLUGIN-1.1.1.MSI4, installing MySQL connector/net 6.8.3 ga download location:/http dev.mysql.com/downloads/connector/net/two, referencing dll:1, installing ef6.0.2;2 with NuGet, installing with NuGet MySql.Data.Entity.EF6

Note: To install with NuGet, the appropriate DLL or configuration information may be missing

Iii. configuring Web. config or app. Config

1. Replace the Entitframework node with the following:

<EntityFrameworkCodeconfigurationtype= "MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"><defaultconnectionfactorytype= "System.Data.Entity.Infrastructure.SqlConnectionFactory, entityframework"/><providers><providerInvariantName= "MySql.Data.MySqlClient"type= "MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /><providerInvariantName= "System.Data.SqlClient"type= "System.Data.Entity.SqlServer.SqlProviderServices, entityframework.sqlserver" /></providers></EntityFramework>

2. Add ConnectionString node:

<connectionstrings><add name="mycontext " connectionstring= " Data source=localhost;port=3306;initial catalog= database name; user Id=mysql login username; password=mysql server password;  "providername="MySql.Data.MySqlClient"/></connectionstrings >

If you do not use the "Generate models and context based on database table fields" feature, you can not read them.

-----------------------------------------------------------------------------

1, VSS obtains this project, this project already implements the function of the page and the database interaction.

FrameWork4.5 EF6

The following are the main implementations: Generate models based on the database table fields and apply to developers at the DAL level.

2, vs2013 Install the extension of EF, can build models and context according to the database table field, tools--extension and update--search "Entity FrameWork Power Tools Beta4", install the extension.

3. Install MySQL Connector Net 6.8.3 32 or 64-bit: http://dev.mysql.com/downloads/file.php?id=450594 (official website, login to download)

2, 3 purpose is to use: Project combat, Project-right-Entity framework-reverse enginner Code First, generate Models folder and inside the. cs file.

The Entity framework connects to the MySQL database and generates the model and DAL layers

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.