transaction on custom repositories

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 Jahr weitere
Hello team,

I am wondering why transaction rollback does not have any effect, even there is an exception. i have used as below.

Please input any workaround.

1. Created DBContext class -- ApplicationDbContext.cs
  
  public partial class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext() {}
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(DataSettingsManager.LoadSettings().ConnectionString);
        }
    }


2. Registered in DependencyRegistrar.cs
            
services.AddDbContext<ApplicationDbContext>();

3.  Used in a submit button, where i have call to multiple custom entity transactions.
try
            {
                using (var context = new ApplicationDbContext())
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        entity = await _applicationService.InsertAsync(entity);
                        entity = await _studentService.InsertAsync(entity);

                        transaction.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
            }
1 Jahr weitere
you can give a try like this

using (var context = new ApplicationDbContext())
{
     using (var transaction = context.Database.BeginTransaction())
       {
            try {
                        entity = await _applicationService.InsertAsync(entity);
                        entity = await _studentService.InsertAsync(entity);

                        transaction.Commit();
              }
             catch (Exception ex)
              {
                  transaction.Rollback();
              }
       }
}

useful link https://www.nopcommerce.com/en/boards/topic/47952/how-to-use-transactions-in-nopcommerce
1 Jahr weitere
I tried similarly, still it didn't worked.

Any suggestion  on workaround pls
1 Jahr weitere
Hello if anyone who faced similar issue, can you suggest?.

Or Someone can confirm its possible or not  pls if you tried.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.