Problems using EF4.1 Code First with MVC3 and MySQL

巧了我就是萌 提交于 2019-12-24 08:38:11

问题


I am following this guide: http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

So that is MVC3 with EF Code First and I am trying to use MySQL instead of SQLSERVER.

So far I have downloaded the MySqlConnector/Net (and also Devart dotConnect). In my web.config I have added the following under

<add name="ProjectContext"
     connectionString="Server=localhost; Database=project; Uid=root; Pwd=pass;"
     providerName="MySql.Data.MySqlClient"/>

Next, I found out that the following also has to be added to the web.config. I don't know why though.

<DbProviderFactories>
  <clear/>
  <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.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>

I have a simple POCO model for a post called Post. I am under the impression that when this compiles, and the lazy loading kicks in, the entity framework should create a table for me that's called 'post' (or 'posts').

However, when this runs, I get the following error: "Table 'project.posts' doesn't exist" indicating that the EF does NOT create this for me.

When I use the dotConnect instead, I get the another error: "Unknown database 'dbo'".

Does anyone have some insight as to what's going on?


回答1:


MySql Connector/NET did not support Entity Framework Code First until version 6.6.

For a tutorial on MVC with Connector/NET see https://blogs.oracle.com/MySqlOnWindows/entry/building_an_mvc_3_application




回答2:


We have already replied to you at our forum here.
Feel free to contact us if you encounter any other problems with our components.



来源:https://stackoverflow.com/questions/5770008/problems-using-ef4-1-code-first-with-mvc3-and-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!