asp.net mvc - Using MySql with Entity Framework 4 and the Code-First Development CTP -


"postprint" itemprop = "text">

I thought I would like the code outline of the unit 4. Instead of using code with SQL Server - Scott Guthrie on Dev There was a bit of experimentation with, I am trying to use MySql here are the relevant parts of my web.config (this is an Asp.Net MVC 2 app):

  & lt ; ConnectionStrings & gt; & Lt; Adding name = "NerdDinners" connectionstring = "server = local host; database = NerdDinners; uid = root; pwd =", ProviderName = "MySql.Data.MySqlClient" /> & Lt; / ConnectionStrings & gt; & Lt; System.data & gt; & Lt; DbProviderFactories & gt; & Lt; Add name = "MySQL data provider" irreversible = "MySql.Data.MySqlClient" Description = type = "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, version = 6.2.3.0" Net Framework Data Provider for MySQL "Culture = Neutral, Public Token = c5687fc88969c44d" / & gt; & Lt; / DbProviderFactories & gt; & Lt; /system.data>  

Like the tutorial, I am hoping for EF4 to automatically generate DB for myself. Instead, it throws a ProviderIncompatibleException, complaining with an internal exception that the NerdDinners database does not exist

Fair enough; I went and created MySQL DB for it, just to see that things will work, and this time instead of another provider irrelevant extension, "DatabaseExists is not supported by the provider".

I accept, this is the first time I am actually going on the outline of the unit (I have been stuck to Sql mostly Linq), and it's all going on Code-First CTP Which has been released last week. That's the reason, said that there's something I'm doing wrong here, or a known problem that's all around?

"itemprop =" text ">

Ok, in the end it has got work with some points of interest.

  • DB can not be created, must already exist
  • You simply do not use a DBContext name to create a connection string for each DB contest a default one (In the above example a connectionstring name must exist with "NerdDinners"), (otherwise it will use SQL)
  • This will use the name of the DBSet name you define your reference as the name of the table To use, be careful By his name it.

Overall, there is a long road, but in the end

** Update Another point to note when using your MVC site using MySQL If you are deployed, then you will most like to add a DataFactory to your web.config. Usually due to differences between MySQL connector and MySQL versions. (Answer received through other sources after scratches of more head) Just add:

  & lt; System.data & gt; & Lt; DbProviderFactories & gt; & Lt; Add name = "MySQL data provider" irreversible = "MySql.Data.MySqlClient" Description = type = "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, version = 6.3.6.0" Net Framework Data Provider for MySQL "Culture = Neutral, Public Token = c5687fc88969c44d" / & gt; & Lt; / DbProviderFactories & gt; & Lt; /system.data>  

As your web.config installs a separate section of version number MySQL.Data.dll you posted it with a good site (also a good To make sure the compatibility of "MySQL DLL is copied as a local" idea.


Comments