0

I'm new to ASP.NET and MVC, trying to move from WinForms. I'm using Visual Studio 2017 Pro, and I am trying to follow some tutorials for connecting to an existing MySQL database. I plan to use the Database First method as the database already exists. I have the following config :-

Windows 10 Pro 64 bit on my PC

VS 2017 Pro MySQL for Visual Studio 2.0.5 MySQL Connector 6.10.4

  • EntityFramework v6.2.0
  • Mysql.Data 6.10.4
  • Mysql.Data.Entity 6.10.4
  • Mysql.Web 6.10.4

I can make a database connection using the Server Explorer, but when I'm using the EDM wizard to create the model from the database, the connection isn't showing in the drop-down box, and if I try to create a new one, the MySQL driver doesn't show as an available option, only SQL Server.

I've tried various combinations of MySQL for VS, MySQL Connector, EF and MySQl components (older versions) but I can't seem to find a winning combination.

Has anyone managed to achieve this ? I'm pulling out what's left of my hair. Thanks.

enter image description here enter image description here

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Dugggie
  • 356
  • 5
  • 17
  • 1
    The EDM Wizard requires *designer* support, as half of the model is mappings from the model to the actual database schema. You'll have to find and add the appropriate designer packages. It's also deprecated, along with all the EDMX stuff. EF Core doesn't support it at all. Devs avoid it for valid reasons - hard to version, complex to change. It's *easier* to reverse engineer a database and update the model, mappings as needed – Panagiotis Kanavos Oct 30 '17 at 13:26
  • Thanks for the reply, looks like I have a lot more reading to do if this is deprecated. – Dugggie Oct 30 '17 at 13:55
  • Not as much as you think - it's actually easier to work without EDMX. You *can* reverse engineer classes from the database or views. You shouldn't have one big model with 100s of tables anyway - such models make it very hard to change anything without breaking stuff. EDMX hides the *actual* classes which makes it harder to add, eg read-only properties, methods. – Panagiotis Kanavos Oct 30 '17 at 14:07
  • You can start by mapping only a few tables at a time. Consider your *contexts* as boundaries around business-related entities (yes, I know it sounds like DDD). *Don't* map columsn in a context if you don't actually need them. You'll see it's actually easier to grow your application this way. It's also easier to modularize (ie break it apart) if you find that it grows too big. Try doing that with an EDMX model – Panagiotis Kanavos Oct 30 '17 at 14:10
  • Thanks again Panagiotis, I've started with a couple of basic models to match tables, but it's not very intuitive, especially trying to match foreign keys. I'll soldier on. – Dugggie Oct 30 '17 at 15:03
  • My original problem still stands though if anyone knows the answer. I still cannot make a connection to the MySQL database. I've tried several combinations of EF and mysql connectors but I can't seem to hit on a working combination. – Dugggie Oct 31 '17 at 14:42
  • That's a *different* problem. What do you mean you can't make a connection? What did you try? Did you create a `MySqlConnection` ? Is the connection string correct? – Panagiotis Kanavos Oct 31 '17 at 14:44
  • Hi again Panagiotis, please take a look at the image on the original post. I can make a db connection in the server explorer (which is showing on the left). So that part works (I believe this is done by the MySQL for Visual Studio). When I try to connect to the database, for example when adding an ADO Data Entity Model (Code First From Database), I only see an option for a SQL Server connection, no MySQL. – Dugggie Oct 31 '17 at 15:21
  • When have tried EF 6.1.3 with v6.10.4 of the MySQL Connector and I am able to see the connection settingsf or MySQL, but then I get the following error...Your Project references the latest version of Entity Framework; however an Entity Framework database provider compatible with this version could not be found in your data connection. – Dugggie Oct 31 '17 at 15:27

1 Answers1

0

OK I finally found an answer, I now have EF 6.1.3 and MySQL Connector 6.9.9 installed.

I needed to change the part of the Web.Config file as described by James Wilkins in this post.

Thanks to Panagiotis for your help.

Dugggie
  • 356
  • 5
  • 17