linq2db / docs

Documentation sources and build scripts
3 stars 10 forks source link

Wcf service transaction #17

Open frankiDotNet opened 7 years ago

frankiDotNet commented 7 years ago

If I use your WCF Service, how is it like with transactions. Is the transaction commited if the using of the service context ends? What if the connection is closed before the using block ends (error case) , is the query executed?

sdanyliv commented 7 years ago

Transaction for data modifications starts only for batch queries an commited exactly after execution. For simple update or insert starting transaction is not necessary.

frankiDotNet commented 7 years ago

Ok lets say I have something like this:

using (var db = new DbNorthwindService())
{
  db.BeginTransaction();
 // ..create a person..
 // Person is one table.
  db.Insert(person);

  // Product is another table
  db.Product
    .Where(p => p.UnitsInStock == 0)
    .Set(p => p.Discontinued, true)
    .Update();

    db.CommitTransaction(); 
}

For this situation I would expect that if the transaction is commited , then person is inserted and all products are updated. Is this so?

sdanyliv commented 7 years ago

Try to use BeginBatch and CommitBatch instead.

frankiDotNet commented 7 years ago

Ok so this would do the desired process:

using (var db = new DbNorthwindService())
{
  db.BeginBatch();
 // ..create a person..
 // Person is one table.
  db.Insert(person);

  // Product is another table
  db.Product
    .Where(p => p.UnitsInStock == 0)
    .Set(p => p.Discontinued, true)
    .Update();

    db.CommitBatch(); 
}
sdanyliv commented 7 years ago

It is works for you?

frankiDotNet commented 7 years ago

I hav not tested it yet.. I forgot to put the question mark at the end :-)

frankiDotNet commented 6 years ago

Works like expected! We should add an info to the documentation that batches cover a transaction...