Nieprawidłowa nazwa obiektu „dbo .__ MigrationHistory” za pomocą Database.Create; EF6.02, gdy przekazany zostanie ciąg połączenia

Występuje błąd podczas próby utworzenia bazy danych przy użyciu następującego kodu. Zauważ, że problem nie występuje, jeśli ciąg połączenia nie zostanie przekazany. Problem pojawia się również, gdy uruchamiam program w środowisku IDE. Nie dzieje się tak, jeśli uruchomię program .exe lub uruchomię testy jednostkowe w IDE.

Jeśli jednak baza danych jest tworzona przez uruchomienie testów jednostkowych lub uruchomienie .EXE, to__MigrationHistory tabela jest tworzona w głównej tabeli, a nie w tabelach systemowych.

public Context(string connString, bool AddInitialRecords )
    : base(connString ?? "MyContextName")
{
    this.CheckDatabase(AddInitialRecords);
}

public void CheckDatabase(bool AddInitialRecords)
{
    if (this.Database.Exists())
    {
         // upgrade stuff
    }
    else
    {
       Database.Create();  // error occurs here
        // seeding stuff 
    }
}

Nie mam problemu, jeśli użyję czegoś podobnego

var db1 = new Context();
db1.Database.CreateIfNotExists();

Znalazłem dokumentacjętutaj ale mnie to myli. Instaluję ze „stabilnej kompilacji” z pewnością nie doświadczam czegoś od 2012 roku? Co mogłem zrobić źle z PM?

Komunikat o błędzie problemu to ....

Wystąpił wyjątek System.Data.Entity.Core.EntityCommandExecutionException
HResult = -2146232004 Wiadomość = Wystąpił błąd podczas wykonywania definicji polecenia. Szczegółowe informacje zawiera wyjątek wewnętrzny.
Source = EntityFramework StackTrace: at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands (EntityCommand entityCommand, zachowanie CommandBehavior) InnerException: System.Data.SqlClient.SqlException HResult = -2146232060 Wiadomość = Nieprawidłowa nazwa obiektu 'dbo .__ MigrationHistoria ” Source = .Net SqlClient Data Provider ErrorCode = -2146232060 Class = 16 LineNumber = 1 Number = 208 Procedure = "" Server =. SQLEXPRESS State = 1 StackTrace: at System.Data.SqlClient.SqlConnection.OnError (wyjątek SqlException, Boolean breakConnection , Action`1 wrapCloseInAction) w System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj, logicznej callerHasConnectionLock, logiczna asyncClose) w System.Data.SqlClient.TdsParser.TryRun (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader datastream BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean & dataReady) w System.Data.SqlClient.SqlDataReader.TryConsumeMetaData () w System.Data.SqlClient.SqlDataReader.get_MetaData () w System.Data.SqlClient.SqlCommand.FinishExecuteReader (SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task & task, Boolean asyncWrite) w System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String, TaskCompletionSource`1, Int32 timeout, Task & task, Boolean asyncWrite) w Systemie .Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, metoda String) w System.Data.SqlClient.SqlCommand.ExecuteReader (zachowanie CommandBehavior, metoda String) w System.Data.SqlClient.SqlCommand.ExecuteDbDataReader. zachowanie) w System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher. <> c__DisplayClassb.b__8 () w System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch [TInterceptionContext, TResult] (operacja Func`1, TInterceptionContext interceptionContext, wykonanie Action`1, wykonanie Action`1) w System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader (polecenie DbCommand, Db CommandInterceptionContext interceptionContext) w System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader (zachowanie CommandBehavior) w System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands (EntityCommand entityCommand, CommandBehavior zachowanie) InnerException:

questionAnswers(3)

yourAnswerToTheQuestion