Where is db transaction ?

1 week ago
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.
1 week ago
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();
...
1 week ago
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 ?
1 week ago
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 ;)
6 days ago
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();
}
3 days ago
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 ?
3 days ago
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.
3 days ago
SagarKayasth wrote:
Not written in nopCommerce, You need to handle transaction code.


You save me a day, thanks.