我收到错误
" System.Data.SqlClient.SqlException:无效的对象名称 ' DBO .__ TransactionHistory'"
当我尝试使用EF 6.1.3中的new dbcontext
创建TransactionContext
时。在DBMigrator/Initializer
甚至有机会创建它之前,它似乎是一个使用transactioncontext API的错误,因为这些操作是在事务中完成的。
以下是复制问题的代码
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; }
}
}
}
答案 0 :(得分:1)
我最后做了两件事。
CREATE TABLE [dbo].[__TransactionHistory] (
[Id] [uniqueidentifier] NOT NULL,
[CreationTime] [datetime] NOT NULL,
CONSTRAINT [PK_dbo.__TransactionHistory] PRIMARY KEY ([Id])