Open frankiDotNet opened 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.
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?
Try to use BeginBatch
and CommitBatch
instead.
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();
}
It is works for you?
I hav not tested it yet.. I forgot to put the question mark at the end :-)
Works like expected! We should add an info to the documentation that batches cover a transaction...
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?