0

I know that the default return here is the SQL Server database type, but I need the MySQL database type, the problem is to create a DbContext instance of the specified database type?

Of course, I know that it can also be created by specifying the connectionName, but the database connection string is encrypted and the string needs to be decrypted

The pseudo code is as follows:

public partial class MyDbContext : DbContext
{
    static string mysqlConn = ReadConnectionString(); //Get the encrypted MySQL connection string

    public MyDbContext() : base(mysqlConn)
    {
        // Even if I want to modify the connection string in this way, nor will it throw a connection string malformed exception
        Database.Connection.ConnectionString = DecryptConnectionString(mysqlConn);
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
win10shit
  • 1
  • 2

2 Answers2

0

Ok, it's about what I expected, few of my questions can be answered.

Although I am not too familiar with EntityFramework, by looking at the source code of DbContext, I can almost certainly determine that this is a design flaw, it lacks a constructor like this:


Public DbContext(string connectionString, string providerName)
win10shit
  • 1
  • 2
0

I had same problem and found .Net framework 4.5 needs additional attribute on DbContext class to use MySql as below

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class MySqlContext : DbContext
{
...
}
Kevin Youn
  • 721
  • 6
  • 4