MySQL and Entity Framework 4.0 - Foreign Keys
When generating a model from database in VS2010, I get my tables as entities, but the problem is t开发者_运维知识库hat 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.)
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.
精彩评论