Skip to content

Bulk operations does not require transaction to be performed. #163

@alex-kulakov

Description

@alex-kulakov

Look at the following operation

using(var session = Domain.OpenSession()) {
   _ = session.Query.Insert(() => new TestEntity(session) { Name = "The Awesome Name" });
}

This code will work for some reason. I would expect an exception telling that transaction is required.

There is strange part in Operation

protected void EnsureTransactionIsStarted()
    {
      var accessor = QueryProvider.Session.Services.Demand<DirectSqlAccessor>();
      var notUsed = accessor.Transaction;
    }

I'm pretty sure this part relies on some check within the accessor.Transaction property.
This property checked transaction existence long ago:

public DbTransaction Transaction {
  get {
    TryStartTransaction();
    return service.Transaction;
  }
}

private void TryStartTransaction()
{
  if (Session.Transaction!=null)
    Session.EnsureTransactionIsStarted();
}

but now there is no check so I think check for transaction should be recovered but within extension to force user to open TransactionScope. Otherwise, insert will be executed in auto-commit transactions. I have a feeling that this is not how it should work.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions