MySQL 和实体框架 4.0 - 外键
当在 VS2010 中从数据库生成模型时,我将表作为实体,但问题是未创建外键。
我已经为此苦苦挣扎了好几天,但似乎无法解决问题。 (我在 MSSQL Server 方面有丰富的经验,但客户想要 MySQL)
我正在使用 MySQL 5.1 和 MySQL Workbench 5.2 来创建我的数据库和表。当我读到这篇文章支持外键时,我对所有表都使用 InnoDB 引擎。
接下来我尝试使用 MySQL Connector 6.4.3(我认为这是最新的,不确定)、dotConnect for MySQL、MySQL ODBC Connector 3.* 和 VS2010 sp1。
我读过很多帖子,人们声称可以实现此功能,然后准确复制他们在博客/帖子中提出的内容,但没有生成外键。
这是非常令人沮丧的,因为我安装了 MySQL Connector(早期版本,例如 6.3.*),然后将其卸载,因为较新的博客说下一个版本支持 EF (OO)... 然后事实证明我仍然没有得到我的外键。
任何人都可以请阐明这一点吗? (我将不胜感激。)
When generating a model from database in VS2010, I get my tables as entities, but the problem is that the foreign keys aren't created.
I've been struggling with this for days now and just can't seem to get it right. (I've got fair experience with MSSQL Server, but the client wants MySQL)
I'm using MySQL 5.1 and MySQL Workbench 5.2 to create my databases and tables. I use the InnoDB engine for all my tables as I read this supports foreign keys.
Next I've tried using MySQL Connector 6.4.3 (I think this is the latest one, not sure), dotConnect for MySQL, MySQL ODBC Connector 3.* with VS2010 sp1.
I've read allot of posts where people claim to get this working, then copy exactly what they propose in their blogs/posts, yet no foreign keys gets generated.
This is very frustrating as I install MySQL Connector (Earlier versions eg. 6.3.*) then uninstall it because a newer blog says this next version supports EF (O.O)...
And then it turns out I still don't get my foreign keys.
Can anybody please shed some light on this? (I would greatly appreciate it.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过两周的努力,我终于成功了。
请参阅我假设,如果您在 MySQL 的 EER 中创建外键关系,则表会生成外键(尽管现在我怀疑只有模型中的表才能生成外键,而不是数据库表本身)。您必须自己在表上创建外键(与 MSSQL Server 不同)...
这基本上就是问题所在。虽然现在已经整理好了。
After 2 weeks of struggling I managed to get it right.
See I assumed that if you create foreign key relations in the EER of MySQL, the tables get the foreign keys generated (though now I have a suspicion that only the tables in the model get this, and not the database tables themselves). You have to create the foreign keys on the tables yourself (Unlike MSSQL Server)...
This was basically the problem. Though it's sorted now.