My setup:
I am using the entity framework as my DAL to SQLite v1.0.60.0. I will create a new EF context at my root operation (Say Invoice insert) use it then pass it to my child operations (line items). I want to protect all this in a transaction for obvious reasons. If I manage transactions manually it will work as expected, but if I try to use a transaction scope then I get the null reference exception when I tell the EF to commit the changes.
Stack trace:
at System.Data.SQLite.SQLiteCommand.set_Transaction(SQLiteTransaction value)
at System.Data.SQLite.SQLiteCommand.set_DbTransaction(DbTransaction value)
at System.Data.Common.DbCommand.set_Transaction(DbTransaction value)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at SharpInvoice.Core.Invoice.DataPortal_Insert(MyContext context) in D:\source\Working\Stenco\CslaNew\src\SharpInvoice.Core\Invoice.cs:line 243
I should note that I have enlist=false. If I set enlist=true then I get an ArgumentException: Unable to enlist in transaction, a local transaction already exists with a stack trace of:
at System.Data.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction)
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at SharpInvoice.Core.Invoice.DataPortal_Insert(MyContext context) in D:\source\Working\Stenco\CslaNew\src\SharpInvoice.Core\Invoice.cs:line 243
Am I doing something wrong? I *REALLY* don't want to manage the transactions myself as I have no clean way of passing them back and forth and will need to do some re-architecting. Please advise.