Created
March 27, 2012 08:10
-
-
Save samnaseri/2213903 to your computer and use it in GitHub Desktop.
A temporary solution for solving Invalid Object Name 'dbo.__Examination'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is for scenarios in which your default schema name is not dbo and hence Entity Framework migration is not working properly. | |
// WARNING : Please be advised that this is a naive solution which its purpose is to just show how it could be corrected. You may not use this code without understanding and resolving any potential problem. | |
// For more information go to http://samondotnet.blogspot.com.au/2012/03/why-invalid-object-name.html | |
namespace ES.DataAccess.Migrations | |
{ | |
using System.Data.Entity.Migrations; | |
using System.Data.Entity.Migrations.Model; | |
using System.Data.Entity.Migrations.Sql; | |
using System.Linq; | |
internal sealed class Configuration : DbMigrationsConfiguration<ES.Domain.ExaminationDbContext> | |
{ | |
public Configuration() | |
{ | |
SetSqlGenerator("System.Data.SqlClient", new SamSqlGenerator()); | |
AutomaticMigrationsEnabled = false; | |
} | |
} | |
public class SamSqlGenerator : SqlServerMigrationSqlGenerator | |
{ | |
protected override void Generate(System.Data.Entity.Migrations.Model.CreateTableOperation createTableOperation) | |
{ | |
if (createTableOperation.Name.Contains("__MigrationHistory") && !createTableOperation.Name.StartsWith("dbo.")) | |
{ | |
var newCreateTableOperation = new CreateTableOperation("dbo." + createTableOperation.Name); | |
createTableOperation.Columns.ToList().ForEach(newCreateTableOperation.Columns.Add); | |
base.Generate(newCreateTableOperation); | |
} | |
else | |
base.Generate(createTableOperation); | |
} | |
protected override void GenerateMakeSystemTable(System.Data.Entity.Migrations.Model.CreateTableOperation createTableOperation) | |
{ | |
} | |
protected override void Generate(System.Data.Entity.Migrations.Model.InsertHistoryOperation insertHistoryOperation) | |
{ | |
if (!insertHistoryOperation.Table.StartsWith("dbo.")) | |
insertHistoryOperation = new InsertHistoryOperation("dbo." + insertHistoryOperation.Table, insertHistoryOperation.MigrationId, insertHistoryOperation.Model, null); | |
base.Generate(insertHistoryOperation); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
In my project , I have been experiencing same issue in recent past... Before fixing this issue... I want to reproduce this issue in UAT/ Stage environment...
Did you have any idea... How Can i reproduce this issue? Currently we are using EF6.