I've been using the following method since Entity Framework Code First became available:
public virtual void CreateDatabase()
{
var dbContext = _dbContextLocator.Current;
dbContext.Database.Delete();
dbContext.Database.Create();
dbContext.Database.Initialize(true);
}
Recently, I noticed that when dbContext.Database.Create()
is hit, I get the following exception:
System.Data.SqlServerCe.SqlCeException occurred
Message=The specified table does not exist. [ __MigrationHistory ]
Source=SQL Server Compact ADO.NET Data Provider
ErrorCode=-2147467259
HResult=-2147217865
NativeError=0
StackTrace: at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
InnerException:
If I go to Debug - Exceptions and check Thrown for "Common Language Runtime Exceptions", this causes execution to stop, and I get the above exception. If I uncheck it, the database seems to get created properly, but I get four repeats of the following error statements in my Output window:
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.Entity.dll
A first chance exception of type 'System.Data.EntityCommandExecutionException' occurred in System.Data.Entity.dll
A first chance exception of type 'System.Data.EntityCommandExecutionException' occurred in System.Data.Entity.dll
A first chance exception of type 'System.Data.EntityCommandExecutionException' occurred in System.Data.Entity.dll
Placing a try/catch block around dbContext.Database.Create()
has no effect.
My goal is to create a completely blank database, then fill it with data manually. I do not wish to use the new Migrations feature of Entity Framework.
What can I do to eliminate the first chance exceptions?