Akhil
Akhil

Reputation: 2030

MySQL Data Provider Not Showing in Entity Data Model Wizard

I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database

Environment:

MySQL Server 5.7.21 MySQL for Visual Studio 1.27 Connector/NET 6.10.5 Visual Studio 2015

To Reproduce Issue:

Step 1: Add new item 'Ado.net Entity Data Model' Step 2: Selected 'EF Designer from database' and click 'Next' Step 3: Clicked 'New Connection'

There is no mysql connector available.

Other Details:

  1. I already added "System. Runtime" deal as it shows error when installing Mysql. data. Ef6 from nugget
  2. I changed "CopyLocal= true" in 'System. Data' assembly reference
  3. I tried the same steps in Visual Studio 2017. Here I can see the provider in the step 3 but after click ok dialogue closed instead of showing table list

In Visual Studio 2015 and 17 initial time it shows the provider. when I tried next time it's not displaying Please help. I am checking this for 2 days

Upvotes: 8

Views: 6034

Answers (3)

JDC
JDC

Reputation: 1785

Could it be a 32bit vs 64bit problem?
Example: 64bit driver installed Visual studio is 32bit?
I have that problem all the time with oledb to Informix. your sofware will work perfectly in 64bit, but the tooling is 32bit.

Upvotes: 0

Benjamin RD
Benjamin RD

Reputation: 12034

To start working with VS 2013 and EF 6

  1. Install the MySQL for Visual Studio 1.1.1
  2. Install the Connector/Net 6.8.1 product.
  3. To work with Database first please do the following
    • Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
    • Add the provider to your app/web config file on the providers for Entity Framework section with the following line:
    • Before you run the Wizard compile your application so the new changes are applied.
  4. To work with Model First please do the following
    • Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
    • Add the ADO.Net Entity Model new or existing.
    • Select the T4 template corresponding to MySQL (SSDLToMySQL)
    • Right click on the model and then select Generate Script to Create Database. (A MySQL script should be generated for you to create your database).

Hope this helps a bit.

MySQL for Visual Studio 1.1.1

MySQL Connector/Net 6.8.1 Beta

Upvotes: 2

kara
kara

Reputation: 3455

As MaDOS mentioned, mySql is not realy supported. If you want to use EF anyway you have to do a code-first-attempt.

You have to write the mapping-classes, and tell EF that it should NOT change the db.

Example context with disabled db-changes

public class MySqlDbContext : DbContext
{
    public DbSet<MyOrderClass> Orders { get; set; }

    public MySqlDbContext(IDbConnection connection)
        : base((DbConnection)connection, false)
    {
        Database.SetInitializer<MySqlDbContext>(null); // Disable db-changes by dbContext
    }
}

You main Problem are the data-types. Outside the MS-world not all data-types are supported (Oracle also got some problems with DateTime). In example-class below the "Created"-column is handled as string, which always works. In your .Net-application, you have to implement "converter"-properties which map to the desired type.

Example-Class with mapping-configuration

[Table("TORDERS")]
public class MyOrderClass
{
    [Column("ORDERID")]
    public long Id { get; set; }
    [Column("CREATED")]
    public string CreatedString { get; set; }

    [NotMapped]
    public DateTime? Created
    {
        get
        {
            DateTime tmp;
            if (DateTime.TryParse(this.CreatedString, out tmp))
                return tmp;

            return null;
        }
        set
        {
            this.CreatedString = value.HasValue ? value.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
        }
    }
}


    static void Main(params string[] args)
    {
        MyOrderClass tmp = new MyOrderClass() { CreatedString = "2018-01-01 11:11:11"};

        Console.WriteLine(tmp.Created.ToString()); // This is how you want to work
        tmp.Created = null;
        Console.WriteLine(tmp.CreatedString); // this is surely not what you want to do

        tmp.Created = new DateTime(2018,02,02,10,10,10);
        Console.WriteLine(tmp.CreatedString); // Check if setter works ;)
    }

Im not uptodate which types work, but with this you'll always be able to use EF. We used it some time ago to access an existing db, which hat an awful db-schema anyway, because of the schema we hat to setup the datatypes anyway ;).

Upvotes: 0

Related Questions