Statement: The database is MySQL, I only to the extent of writing SQL statements (no saving process), C # will be the basic ADO Database Access, LINQ Foundation.
This one only does personal study | review function. Novice can refer to, also please master wrong, Thanksgiving.
The Entity Framework (abbreviated EF) is a framework for Microsoft. The function is to deal with the mapping problem of object-oriented and relational database.
We used to be ADO. Accessing the database, Connection.Open (), SQL command, ExecuteNonQuery | DataReader, Connection.close () et cetera
Then load the select result into a DataTable | List<class>, wait.
Write for a long time you will find that such a process is very repetitive, the code is not neat and intuitive, a big reason is that the relational database thinking and object-oriented is not very consistent caused.
Another bad thing is that when you replace a database, there is an incompatibility problem with statements that may require bulk substitution.
The Entity Framework allows you to access data directly from any database without having to write SQL statements.
The so-called mapping is to write each SQL table a corresponding class,column= attribute, and then write out the relationship between them. The relationship here refers to the paradigm (1 to 0, 1 to many, many to many)
Then synchronize the database by manipulating the object, a bit of MVC, the concept of model--view
Let's start with the installation configuration.
I did most of the day, not a very complete result, and finally can only use EF 6.1.1, with the Mysql 5.x Code first mode (class and data sheet is handwritten), do not make the designer page automatically created.
I used Visual Studio Ultimate, originally EF 5.0, to download the installation through NuGet.
Because I use MySQL, I have to install connetor/net 6.9.3. Download http://dev.mysql.com/downloads/connector/net/6.9.html
There is also MySQL for Visual Studio. Download http://dev.mysql.com/downloads/windows/visualstudio/1.2.html
After installation, copy the DLL into the bin. Generally in: C:\Program files\mysql\mysql Connector Net 6.9.3\assemblies\v4.5\ DLL file
MySql.Data.dll
MySql.Data.Entity.EF6.dll
MySql.Web.dll
Then configure the Web Config
<connectionStrings> <add name= "Somenameyourlike " Providername=" connectionstring= " server=110.100.45.100;database=databasename;uid=username;password=password; /> </connectionstrings>
<compilation debug="true" targetframework="4.5"> <assemblies> <add assembly="System.Data.Entity, version=4.0.0.0, Culture=neutral, publickeytoken=b77a5c561934e089" /> <add assembly="Mysql.data, version=6.9.3.0, Culture=neutral, publickeytoken=c5687fc88969c44d" /> </assemblies > </compilation>
<entityFramework> <defaultconnectionfactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> <providers> <provider invariantname="MySql.Data.MySqlClient"Type="MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity.EF6"/><provider invariantname="System.Data.SqlClient"Type="System.Data.Entity.SqlServer.SqlProviderServices,Entityframework.sqlserver"/></providers> </entityFramework>
That's All right!
Entity Framework with MySQL learning Note one (install)