Exemplo n.º 1
0
        /// <summary>
        /// Creates the entity connection with wrappers.
        /// </summary>
        /// <param name="entityConnectionString">The original entity connection string.</param>
        /// <param name="wrapperProviders">List for wrapper providers.</param>
        /// <returns>EntityConnection object which is based on a chain of providers.</returns>
        public static EntityConnection CreateEntityConnectionWithWrappers(string entityConnectionString, params string[] wrapperProviders)
        {
            EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder(entityConnectionString);

            // if connection string is name=EntryName, look up entry in the config file and parse it
            if (!String.IsNullOrEmpty(ecsb.Name))
            {
                var connStr = System.Configuration.ConfigurationManager.ConnectionStrings[ecsb.Name];
                if (connStr == null)
                {
                    throw new ArgumentException("Specified named connection string '" + ecsb.Name + "' was not found in the configuration file.");
                }

                ecsb.ConnectionString = connStr.ConnectionString;
            }

            MetadataWorkspace workspace;

            if (!metadataWorkspaceMemoizer.TryGetValue(ecsb.ConnectionString, out workspace))
            {
                workspace = CreateWrappedMetadataWorkspace(ecsb.Metadata, wrapperProviders);
                metadataWorkspaceMemoizer.Add(ecsb.ConnectionString, workspace);
            }

            var storeConnection = DbProviderFactories.GetFactory(ecsb.Provider).CreateConnection();

            storeConnection.ConnectionString = ecsb.ProviderConnectionString;
            var newEntityConnection = new EntityConnection(workspace, DbConnectionWrapper.WrapConnection(ecsb.Provider, storeConnection, wrapperProviders));

            return(newEntityConnection);
        }
        /// <summary>
        /// Gets the provider manifest token.
        /// </summary>
        /// <param name="connection">The database connection.</param>
        /// <returns>Provider Manfiest Token suitable for inclusion in SSDL file and connection string</returns>
        /// <remarks>
        /// The provider manifest token is created by concatenating wrapped provider invariant name and its
        /// token separated by semicolon, for example when wrapping SqlClient for SQL Server 2005 the provider
        /// manifest token will be "System.Data.SqlClient;2005"
        /// </remarks>
        protected override string GetDbProviderManifestToken(DbConnection connection)
        {
            DbConnectionWrapper wrapper           = (DbConnectionWrapper)connection;
            DbConnection        wrappedConnection = wrapper.WrappedConnection;
            DbProviderServices  services          = DbProviderServices.GetProviderServices(wrappedConnection);

            string token = wrapper.WrappedProviderInvariantName + ";" + services.GetProviderManifestToken(wrappedConnection);

            return(token);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Wraps the connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="wrapperProviderInvariantNames">The wrapper provider invariant names.</param>
        /// <returns>Wrapped connection.</returns>
        internal static DbConnection WrapConnection(DbConnection connection, params string[] wrapperProviderInvariantNames)
        {
            foreach (string invariantName in wrapperProviderInvariantNames)
            {
                DbProviderFactory factory   = DbProviderFactories.GetFactory(invariantName);
                var connectionWrapper       = factory.CreateConnection();
                DbConnectionWrapper wrapper = (DbConnectionWrapper)connectionWrapper;
                wrapper.WrappedConnection = connection;
                connection = connectionWrapper;
            }

            return(connection);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Wraps the connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="wrapperProviderInvariantNames">The wrapper provider invariant names.</param>
        /// <returns>Wrapped connection.</returns>
        public static DbConnection WrapConnection(string providerInvariantName, DbConnection connection, params string[] wrapperProviderInvariantNames)
        {
            if (wrapperProviderInvariantNames != null)
            {
                string previousWrapperInvariantName = null;
                foreach (string wrapperInvariantName in wrapperProviderInvariantNames)
                {
                    DbProviderFactory factory   = DbProviderFactories.GetFactory(wrapperInvariantName);
                    var connectionWrapper       = factory.CreateConnection();
                    DbConnectionWrapper wrapper = (DbConnectionWrapper)connectionWrapper;
                    wrapper.WrappedConnection            = connection;
                    wrapper.wrappedProviderInvariantName = previousWrapperInvariantName == null ? providerInvariantName : previousWrapperInvariantName;
                    connection = connectionWrapper;
                    previousWrapperInvariantName = wrapperInvariantName;
                }
            }

            return(connection);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbTransactionWrapper"/> class.
 /// </summary>
 /// <param name="wrappedTransaction">The wrapped transaction.</param>
 /// <param name="connection">The connection.</param>
 protected DbTransactionWrapper(DbTransaction wrappedTransaction, DbConnectionWrapper connection)
 {
     this.wrappedTransaction = wrappedTransaction;
     this.connectionWrapper = connection;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbTransactionWrapper"/> class.
 /// </summary>
 /// <param name="wrappedTransaction">The wrapped transaction.</param>
 /// <param name="connection">The connection.</param>
 protected DbTransactionWrapper(DbTransaction wrappedTransaction, DbConnectionWrapper connection)
 {
     this.wrappedTransaction = wrappedTransaction;
     this.connectionWrapper  = connection;
 }