我已经为 MySql 数据库设置了实体框架 4.4.0 (EF5) 代码首次迁移,但是当我运行 Add-Migration 命令时,我总是将 dbo 预先添加到表名中,如下所示:
CreateTable(
"dbo.Fields",
c => new
{
FieldId = c.Int(nullable: false, identity: true),
FieldTypeId = c.Int(nullable: false),
Name = c.String(nullable: false, unicode: false),
Description = c.String(unicode: false),
CodeList = c.String(unicode: false),
Mask = c.String(unicode: false),
})
.PrimaryKey(t => t.FieldId)
.ForeignKey("dbo.FieldTypes", t => t.FieldTypeId, cascadeDelete: true)
.Index(t => t.FieldTypeId);
我正在使用 Devart 数据库提供程序,我的迁移配置类如下所示:
internal sealed class Configuration : DbMigrationsConfiguration<mydbcontext>
{
public Configuration()
{
// Create a custom connection to specify the database and set a SQL generator for MySql.
var connectionInfo =
MySqlConnectionInfo.CreateConnection("<<myconnectionstring>>");
TargetDatabase = connectionInfo;
SetSqlGenerator(connectionInfo.GetInvariantName(), new MySqlEntityMigrationSqlGenerator());
var config = MySqlEntityProviderConfig.Instance;
config.Workarounds.IgnoreSchemaName = true;
AutomaticMigrationsEnabled = false;
}
protected override void Seed(CloudDataSetDbContext context)
{
}
}
由于某种原因,未考虑 IgnoreSchemaName = true 。
我将 Devart 数据库提供程序添加到 web.config 文件中,如下所示:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.MySql" />
<add name="dotConnect for MySQL" invariant="Devart.Data.MySql" description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql, Version=6.80.350.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
我还添加了一个程序集重定向,因为 Devart 需要这样:
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="4.3.1.0" newVersion="4.4.0.0" />
</dependentAssembly>
有人可以帮我吗?谢谢,史蒂文。