Where is db transaction ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 年 前
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 年 前
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 年 前
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 年 前
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 年 前
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 年 前
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 年 前
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 年 前
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.