public virtual IDbConnection OpenDbConnection(string namedConnection)
        {
            if (!NamedConnections.TryGetValue(namedConnection, out var factory))
            {
                throw new KeyNotFoundException($"No factory registered is named {namedConnection}");
            }

            IDbConnection connection = factory.AutoDisposeConnection
                ? new OrmLiteConnection(factory)
                : factory.OrmLiteConnection;

            // moved setting up the ConnectionFilter to OrmLiteConnection.Open
            // connection = factory.ConnectionFilter(connection);
            connection.Open();

            return(connection);
        }
        public static IDbConnection CreateDbConnection(string namedConnection)
        {
            if (namedConnection == null)
            {
                throw new ArgumentNullException(nameof(namedConnection));
            }

            if (!NamedConnections.TryGetValue(namedConnection, out var factory))
            {
                throw new KeyNotFoundException("No factory registered is named " + namedConnection);
            }

            IDbConnection connection = factory.AutoDisposeConnection
                ? new OrmLiteConnection(factory)
                : factory.OrmLiteConnection;

            return(connection);
        }
        public IDbConnection OpenDbConnection(string connectionKey)
        {
            OrmLiteConnectionFactory factory;

            if (!NamedConnections.TryGetValue(connectionKey, out factory))
            {
                throw new KeyNotFoundException("No factory registered is named " + connectionKey);
            }

            IDbConnection connection = factory.AutoDisposeConnection
                ? new OrmLiteConnection(factory)
                : factory.OrmLiteConnection;

            connection = factory.ConnectionFilter(connection);
            connection.Open();

            return(connection);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="namedConnection"></param>
        /// <returns></returns>
        public virtual IDbConnection OpenDbConnection(string namedConnection)
        {
            DefaultConnectionFactory factory;

            if (!NamedConnections.TryGetValue(namedConnection, out factory))
            {
                throw new KeyNotFoundException("No factory registered is named " + namedConnection);
            }

            IDbConnection connection = factory.AutoDisposeConnection
                ? new DefaultConnection(factory)
                : factory.DefaultConnection;

            //moved setting up the ConnectionFilter to OrchardConnection.Open
            //connection = factory.ConnectionFilter(connection);
            connection.Open();

            return(connection);
        }