Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, January 24, 2020 6:08 PM
I was following a tutorial for using MySQL with EF6 and created an MVC5 app, naming it TestUniversity.
I ran "Install-Package MySql.ConnectorNET.Entity -Version 6.8.3.2" in Package Manager Console and got many lines including:
Successfully installed 'MySql.ConnectorNET.Data 6.8.3' to TestUniversity
The references include:
MySql.Data
MySql.Data.Entity.EF6
In the root Web.Config:
<connectionStrings>
<add name="MyDbContextConnectionString" providerName="MySql.Data.MySqlClient"
connectionString="server=<myserver>;UserId=<myuserid>;
database=Track;CharSet=utf8;Persist Security Info=True"/>
</connectionStrings>
I created Models named Course.cs, Enrollment.cs, and Student.cs
I right-click the Models Folder and select Add > Controller
In the dialog I select
MVC 5 Controller with views, using Entity Framework and click the Add button
I fill out Add Controller dialog with:
Student (TestUniversity.Models)
MyDbContext (TestUniversity.DAL)
Generate Views
Reference Script Libraries
Use a layout page
StudentController
And click the Add button
I get this Error window:
There was an error running the selected code generator:
'Unable to retrieve metadata for 'TestUniversity.Models.Student', Unable to find
the requested .Net Framework Data Provider. It may not be installed.
What went wrong and how can I fix it?
Thanks
All replies (7)
Friday, January 24, 2020 7:01 PM
You need the MySQL data provider information in the web.comfig too
Friday, January 24, 2020 7:49 PM
Thank you. I looked further in the root Web.Config. It contains:
<DbProviderFactories>
<remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
Does that provide the needful?
Thanks,
Friday, January 24, 2020 8:09 PM
Oh, wait. I also found this:
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
So I changed it to: <provider invariantName="MySql.Data.MySqlClient" type="MySQL.Data.Entity.EF6" /> inside the <providers> element.
It is either wrong or not complete enough: Now I get:
There was an error running the selected code generator:
'Exception has been thrown by the target of an invocation.'
Friday, January 24, 2020 9:00 PM
IMO, you should use the EF 6 DB first approach in a dummy console program, becuase it generates the connectionstring and provider information is a generated app.config. You can then copy the information to your Web.config.
Saturday, January 25, 2020 1:30 AM
>EF 6 DB first approach in a dummy console program
Thank you. I will give that a try.
Tuesday, January 28, 2020 2:37 PM
>IMO, you should use the EF 6 DB first approach in a dummy console program
I am having difficulty finding examples/instructions of sufficient detail to do this. Can you supply a link to an appropriate example?
Thank you.
Thursday, January 30, 2020 2:31 AM
Hi JonJacobs,
If you want an EF 6 DB first example, you can directly refer to the example on Microsoft official website, which is it's link:
/en-us/ef/ef6/modeling/designer/workflows/database-first
Best Regards,
YongQing.