Where is db transaction ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 yıl önce
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 yıl önce
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 yıl önce
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 yıl önce
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 ;)
1 yıl önce
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();
}
1 yıl önce
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 ?
1 yıl önce
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.
1 yıl önce
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.