in order to learn the ORM, chose the EntityFramework, experienced three days and two nights of suffering, n times wrong, in the group of the help of master, finally succeeded, now will my mind history record down, one is let oneself have a record, another is let other people less go some detours.
My development environment is win8+vs2013, the database environment is MySQL (wampserver)
1. Download MySQL connector/net 6.8.3
Address: http://dev.mysql.com/downloads/connector/net/
You also need to download a MySQL for VisualStudio version that you can use to reference MySQL in the data source in VS
Address: "Mysql for Visual Studio" http://www.05sun.com/downinfo/97255.html
2, download and install EF6 (I do not know if this step is necessary, you can try and tell me, because there are also installed in NuGet, do not know whether it is a meaning, the following will write the concrete method)
Address: http://www.microsoft.com/en-us/download/details.aspx?id=40762
3. Open VS2012, create a new project
4, in the project first install EF6.
Click "Package Manager Console".
5. The interface will appear below the code
6. After "Pm>", enter:
install-PackageEntityFramework
7. Re-enter:Install-package MySql.Data.Entity.EF6
8, pay attention to a little, "here from upstream cold Dragon Blog", must add that paragraph, the final show. (In fact, my build is app. config
At this point, if you add the ADO entity model directly, there are the following errors:
Note: The provider generated in App. config is problematic when you manually add a red line:
<provider invariantname="MySql.Data.MySqlClient " type= " MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
9, regenerate the entire solution, in the project right-"add-" New item
10. Select: Data-"ADO Entity Data Model"
11. Select the EF designer from the database, which is the Dbfirst design mode, and if you select Code first from the database, you are creating the database from the codebase.
Because I chose to build a good MySQL database, so I chose the first item.
11. Select "New Connection"-"Change"-"MySQL"
12. Enter MySQL information and select the appropriate database after you determine
13, after the selection is as shown, and then click "Next"
14, tick the table used, click "Done"
15, now we have set up a EF6 environment, to a step program to try
Add a "Web Form", default "WebForm1.aspx", add a Label control to it, open the daemon, write the following code
protected void Page_Load (object sender, EventArgs e)
{
Kfclubentities en = new kfclubentities ();
This. Label1.Text = en. Serviceman.firstordefault (). Serviceman_name;
}
Run by F5, I'm assuming that the table structure and the data in the table have been built, and you can do it by LINQ to SQL.
Well, first write this, as for the development after the migration to Ubuntu, you have to try again tomorrow.