Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wcf service transaction #17

Open
frankiDotNet opened this issue Jun 7, 2017 · 7 comments
Open

Wcf service transaction #17

frankiDotNet opened this issue Jun 7, 2017 · 7 comments

Comments

@frankiDotNet
Copy link

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
Copy link
Member

sdanyliv commented Jun 8, 2017

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
Copy link
Author

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
Copy link
Member

sdanyliv commented Jun 8, 2017

Try to use BeginBatch and CommitBatch instead.

@frankiDotNet
Copy link
Author

frankiDotNet commented Jun 8, 2017

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
Copy link
Member

sdanyliv commented Jun 8, 2017

It is works for you?

@frankiDotNet
Copy link
Author

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

@frankiDotNet
Copy link
Author

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

@MaceWindu MaceWindu transferred this issue from linq2db/linq2db May 26, 2019
@MaceWindu MaceWindu reopened this May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants