0

I have migrated SQL2012 Database to MySQL, apart from one issue.

I get the following error when I connect to the MySQL Database.

An exception occurred while initializing the database.

InnerException for details: Schema specified is not valid. Errors: (0,0) : error 0040: The Type nvarchar(max) is not qualified with a namespace or alias. Only primitive types can be used without qualification.

This occurs for every String property in my classes.

I have tried the following:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        { modelBuilder.HasDefaultSchema(String.Empty);}

However I still get the error.

Does anybody have suggestions that may resolve the issue.

I have also tried to generate a MySQL migration but I get the following error:

No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Is there a way of setting the MySQLProvider in Code?

Here is my DBConfiguration:

    public class EF6MySQLDbConfiguration : DbConfiguration
  {
    public EF6MySQLDbConfiguration()
    {
      if (CustomConnectionFactory.ServerName == "MySQL")
      {
        SetExecutionStrategy(MySql.Data.Entity.MySqlProviderInvariantName.ProviderName, () => new MySql.Data.Entity.MySqlExecutionStrategy());
        AddDependencyResolver(new MySql.Data.Entity.MySqlDependencyResolver());
        //Type t = typeof(MySqlProviderServices);
      }
      SetDefaultConnectionFactory(new CustomConnectionFactory());
    }

To overcome the problem when migrating the history table I added:

public Configuration()
    {
        AutomaticMigrationsEnabled = false;

        if (EF6MySQL.DataAccess.CustomConnectionFactory.ServerName == "MySQL")
        {
          SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
          SetHistoryContextFactory("MySql.Data.MySqlClient", (conn, schema) => new MySql.Data.Entity.MySqlHistoryContext(conn, schema)); 
        }
    }
RentUrApp
  • 1
  • 3
  • Please, explain a little bit more how your original model was, and how you migrated it. Depending on what you're exactly doing, perhaps you need to update the model for the new database type. – JotaBe Dec 16 '14 at 10:32
  • The model was created using Code First from Classes and the Add-Migration in Package manager console. I was originally targeting SQL2012 to generate the migration. MySQL automatically translates nvarchar(max) to longtext. I need the flexibility to be able to run either database backend. – RentUrApp Dec 16 '14 at 14:22
  • I'm sorry I still don't understand if you're trying to create the new MySQL db, from a SQL Server migration, or whatever. Please, be more specific, so what you already have done and what you're tryign to do in a much more clear way. I can't understand the real problem. Please, edit your question and add all the possible info. It's clear that you are using the sql server sql migration generator against a MySQL db, but I don't know why, without seeing your configuration and code. – JotaBe Dec 17 '14 at 10:27
  • I already have migrations generated and just wish to switch to MySQL as a user setting in code. – RentUrApp Dec 18 '14 at 15:23

1 Answers1

0

The solution is to add the following line:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
  if (CustomConnectionFactory.ServerName == "MySQL")
  {
    modelBuilder.Properties<String>().Configure(c => c.HasColumnType("longtext"));
  }}

The second answer provided here contained invaluable information to setup the 2 different databases.

Community
  • 1
  • 1
RentUrApp
  • 1
  • 3