Database code-first migration problem (EF6.1.3, dotConnector for MySql 8.3.379)
Posted: Mon 30 Mar 2015 21:40
Hello devart Team,
Even though I put
---
MySqlEntityProviderConfig config = MySqlEntityProviderConfig.Instance;
config.Workarounds.IgnoreSchemaName = true;
config.Workarounds.IgnoreDboSchemaName = true;
----
in Context constructor, I am still seeing "dbo." prefix in automatically generated migration code by Package Manager Console (> add-migration test).
Is this expected behavior or is there an option to avoid this?
(For MySQL Connector/Net, I fixed this issue by setting code generator, but I don't see this in devart dotConnector for MySQL)
---
CodeGenerator = new MySqlMigrationCodeGenerator(); // does not exist in devart lib, also cannot assign "new MySqlEntityMigrationSqlGenerator()"
---
The following are the codes I tested.
--------------
/* Program.cs */
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using Devart.Data.MySql.Entity.Configuration;
namespace dotConnectForMySqlTest
{
public class Student
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }
//public string NewProperty { get; set; } // newly added property
}
public class SchoolContext : DbContext
{
public SchoolContext()
{
MySqlEntityProviderConfig config = MySqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.MySql.Entity.Configuration.DeleteDatabaseBehaviour.Database;
config.Workarounds.IgnoreSchemaName = true;
config.Workarounds.IgnoreDboSchemaName = true;
Database.SetInitializer(new CreateDatabaseIfNotExists<SchoolContext>());
}
public DbSet<Student> Students { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
Student stud = new Student() { StudentName = "New Student" };
ctx.Students.Add(stud);
ctx.SaveChanges();
}
}
}
}
--------------
/* Configuration.cs */
using System.Data.Entity.Migrations;
using Devart.Data.MySql.Entity.Migrations;
namespace dotConnectForMySqlTest
{
internal sealed class Configuration : DbMigrationsConfiguration<SchoolContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = true;
SetSqlGenerator(MySqlConnectionInfo.InvariantName, new MySqlEntityMigrationSqlGenerator());
ContextKey = "dotConnectForMySqlTest.SchoolContext";
}
protected override void Seed(SchoolContext context)
{
// This method will be called after migrating to the latest version.
}
}
}
--------------
/* 201503302136166_test.cs (automatically generated)*/
namespace dotConnectForMySqlTest.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class test : DbMigration
{
public override void Up()
{
AddColumn("dbo.Students", "NewProperty", c => c.String());
}
public override void Down()
{
DropColumn("dbo.Students", "NewProperty");
}
}
}
Even though I put
---
MySqlEntityProviderConfig config = MySqlEntityProviderConfig.Instance;
config.Workarounds.IgnoreSchemaName = true;
config.Workarounds.IgnoreDboSchemaName = true;
----
in Context constructor, I am still seeing "dbo." prefix in automatically generated migration code by Package Manager Console (> add-migration test).
Is this expected behavior or is there an option to avoid this?
(For MySQL Connector/Net, I fixed this issue by setting code generator, but I don't see this in devart dotConnector for MySQL)
---
CodeGenerator = new MySqlMigrationCodeGenerator(); // does not exist in devart lib, also cannot assign "new MySqlEntityMigrationSqlGenerator()"
---
The following are the codes I tested.
--------------
/* Program.cs */
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using Devart.Data.MySql.Entity.Configuration;
namespace dotConnectForMySqlTest
{
public class Student
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }
//public string NewProperty { get; set; } // newly added property
}
public class SchoolContext : DbContext
{
public SchoolContext()
{
MySqlEntityProviderConfig config = MySqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.MySql.Entity.Configuration.DeleteDatabaseBehaviour.Database;
config.Workarounds.IgnoreSchemaName = true;
config.Workarounds.IgnoreDboSchemaName = true;
Database.SetInitializer(new CreateDatabaseIfNotExists<SchoolContext>());
}
public DbSet<Student> Students { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
Student stud = new Student() { StudentName = "New Student" };
ctx.Students.Add(stud);
ctx.SaveChanges();
}
}
}
}
--------------
/* Configuration.cs */
using System.Data.Entity.Migrations;
using Devart.Data.MySql.Entity.Migrations;
namespace dotConnectForMySqlTest
{
internal sealed class Configuration : DbMigrationsConfiguration<SchoolContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = true;
SetSqlGenerator(MySqlConnectionInfo.InvariantName, new MySqlEntityMigrationSqlGenerator());
ContextKey = "dotConnectForMySqlTest.SchoolContext";
}
protected override void Seed(SchoolContext context)
{
// This method will be called after migrating to the latest version.
}
}
}
--------------
/* 201503302136166_test.cs (automatically generated)*/
namespace dotConnectForMySqlTest.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class test : DbMigration
{
public override void Up()
{
AddColumn("dbo.Students", "NewProperty", c => c.String());
}
public override void Down()
{
DropColumn("dbo.Students", "NewProperty");
}
}
}