Show / Hide Table of Contents

    DataContext.CurrentConnection Property

    .NET Standard 2.x

    Gets an IAdoDbConnection object which can be used to get detailed information about the database connection, as well as open or close the database connection.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

       public virtual IAdoDbConnection CurrentConnection { get; }
    

    Property Value

    SnapObjects.Data.IAdoDbConnection

    An IAdoDbConnection object which can be used to get more information about the database connection, open or close the database connection.

    Examples

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

    using System;
    
    namespace Appeon.ApiDoc.DataContextExamples
    {
        public class CurrentConnectionExample
        {
            private readonly SchoolContext _context;
            public CurrentConnectionExample(SchoolContext context)
            {
                _context = context;
            }
    
            public void Example()
            {
                var conn = _context.CurrentConnection;
    
                // Shows the connection type of the current DataContext.
                Console.WriteLine("Connection Type = {0}", conn.GetType());
    
                /* This code example produces the following output:
                
                Connection Type = SnapObjects.Data.SqlServer.SqlServerAdoDbConnection
                */
    
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon