在 MVC3 和 MySQL 中使用 EF4.1 Code First 时出现的问题
我正在遵循本指南:
所以那就是MVC3 与 EF Code First,我尝试使用 MySQL 而不是 SQLSERVER。
到目前为止,我已经下载了 MySqlConnector/Net(以及 Devart dotConnect)。 在我的 web.config 中,我在“下一步”下添加了以下内容
<add name="ProjectContext"
connectionString="Server=localhost; Database=project; Uid=root; Pwd=pass;"
providerName="MySql.Data.MySqlClient"/>
,我发现以下内容也必须添加到 web.config 中。我不知道为什么。
<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>
我有一个简单的 POCO 模型,用于名为 Post 的帖子。 我的印象是,当编译时,延迟加载开始,实体框架应该为我创建一个名为“post”(或“posts”)的表。
但是,当运行时,我收到以下错误:“表 'project.posts' 不存在”,表明 EF 不会为我创建此表。
当我使用 dotConnect 时,我收到另一个错误:“未知数据库‘dbo’”。
有人知道发生了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.
MySql Connector/NET 在版本 6.6 之前不支持实体框架代码优先。
有关使用 Connector/NET 的 MVC 教程,请参阅 https://blogs.oracle.com/MySqlOnWindows/entry /building_an_mvc_3_application
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