Where is db transaction ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
один год назад
In v4.50.3, nop use Linq2DB to access the database. But, I cannot find any transactions code in nop. Can someone tell me where the transactions are handled ? Thanks a lot.
один год назад
There are some uses in  \Libraries\Nop.Data\EntityRepository.cs
E.g.,
public virtual async Task InsertAsync(IList<TEntity> entities, bool publishEvent = true)
{
    if (entities == null)
        throw new ArgumentNullException(nameof(entities));

   using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
    await _dataProvider.BulkInsertEntitiesAsync(entities);
    transaction.Complete();
...
один год назад
Thanks! This is the scenario that insert multi rows into the one table. But, if I want to insert data into the two tables, does nop handle the transaction for me in this scenario ?
один год назад
I believe that nopC uses the DataConnection which is described in the Linq2Db docs.

(In any case, you may just want to test it to see that it behaves in the way you want ;)
один год назад
Ho.Chun wrote:
Thanks! This is the scenario that insert multi rows into the one table. But, if I want to insert data into the two tables, does nop handle the transaction for me in this scenario ?


We use above link for transaction example, given by New York and its working fine for us. Below example for use transaction with multiple example.
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
  try
  {
     // your logic
    await _dataProvider.UpdateEntityAsync(product);
  }
  catch (Exception ex)
  {
     transaction.Dispose();
    continue;
  }
  try
  {
     // your logic
    await _dataProvider.UpdateEntityAsync(ProductCategory);
  }
  catch (Exception ex)
  {
     transaction.Dispose();
    continue;
  }
  
  transaction.Complete();
}
один год назад
SagarKayasth wrote:
We use above link for transaction example, given by New York and its working fine for us. Below example for use transaction with multiple example.

Is this code written in nopCommerce source code ? Or I need to handle the transaction by myself ?
один год назад
Ho.Chun wrote:
We use above link for transaction example, given by New York and its working fine for us. Below example for use transaction with multiple example.
Is this code written in nopCommerce source code ? Or I need to handle the transaction by myself ?


Not written in nopCommerce, You need to handle transaction code.
один год назад
SagarKayasth wrote:
Not written in nopCommerce, You need to handle transaction code.


You save me a day, thanks.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.