Show / Hide Table of Contents

    DataContext.CurrentTransaction Property

    .NET Standard 2.x

    Gets an IAdoDbTransaction object which can be used to get information about the database transaction, as well as commit or roll back the transaction.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

       public virtual IAdoDbTransaction CurrentTransaction { get; }
    

    Property Value

    SnapObjects.Data.IAdoDbTransaction

    An IAdoDbTransaction object which can be used to get information about the database transaction, as well as commit or roll back the transaction.

    Examples

    The following code example demonstrates how to get the transaction type from the DataContext object.

    using System;
    
    namespace Appeon.ApiDoc.DataContextExamples
    {
        public class CurrentTransactionExample
        {
            private readonly SchoolContext _context;
            public CurrentTransactionExample(SchoolContext context)
            {
                _context = context;
            }
    
            public void Example()
            {
                // Starts the transaction.
                _context.BeginTransaction();
    
                // Gets the current transaction.
                var conn = _context.CurrentTransaction;
    
                // Rolls back the transaction to end it.
                conn.Rollback();
    
                // Shows the transaction type of the current DataContext.
                Console.WriteLine("Transaction Type = {0}", conn.GetType());
    
                /* This code example produces the following output:
                
                Transaction Type = SnapObjects.Data.AdoDbTransaction
                */
    
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon