entity framework - System.Data.SqlClient.SqlException: Invalid object name 'dbo.__TransactionHistory' -
i error
"system.data.sqlclient.sqlexception: invalid object name 'dbo.__transactionhistory'."
when try creating new dbcontext
using transactioncontext
in ef 6.1.3. seems bug it's using transactioncontext api before dbmigrator/initializer
has chance create since these operations done within transaction.
below code replicates 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; } } } }
i ended doing 2 things.
- manually run sql
create table [dbo].[__transactionhistory] ( [id] [uniqueidentifier] not null, [creationtime] [datetime] not null, constraint [pk_dbo.__transactionhistory] primary key ([id])
- creating commitfailurehandler overrides begantransaction not call base method until table has been created
Comments
Post a Comment