I get the error
"System.Data.SqlClient.SqlException: Invalid object name 'dbo.__TransactionHistory'."
when I try creating a new dbcontext
using the TransactionContext
in EF 6.1.3. It seems like a bug where it's using the transactioncontext API before the DBMigrator/Initializer
even has a chance to create it since these operations are done within a transaction.
Below is the code that replicates the problem
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServer;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
new SomeDbContext().Database.Initialize(false);
}
public class Person
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetTransactionHandler(SqlProviderServices.ProviderInvariantName, () => new CommitFailureHandler());
}
}
[DbConfigurationType(typeof(MyConfiguration))]
public class SomeDbContext : DbContext
{
static SomeDbContext()
{
Database.SetInitializer(new DropCreateDatabaseAlways());
}
public SomeDbContext()
: base(@"Data Source=.;Initial Catalog=SomeDbContext;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=1;")
{
}
public virtual DbSet People { get; set; }
}
}
}