/// <summary>
        ///     由数据库连接串名称创建连接对象
        /// </summary>
        /// <param name="connectionStringName">数据库连接串名称</param>
        /// <returns></returns>
        private static DbConnection CreateConnectionWrapper(string connectionStringName)
        {
            PublicHelper.CheckArgument(connectionStringName, "connectionStringName");

            string providerInvariantName = "System.Data.SqlClient";
            string connectionString = null;
            ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings[connectionStringName];
            if (connectionStringSetting != null)
            {
                providerInvariantName = connectionStringSetting.ProviderName;
                connectionString = connectionStringSetting.ConnectionString;
            }
            if (connectionString == null)
            {
                throw PublicHelper.ThrowComponentException("名称为“" + connectionStringName + "”数据库连接串的ConnectionString值为空。");
            }
            string wrappedConnectionString = "wrappedProvider=" + providerInvariantName + ";" + connectionString;
            EFCachingConnection connection = new EFCachingConnection
            {
                ConnectionString = wrappedConnectionString,
                CachingPolicy = CachingPolicy.CacheAll,
                Cache = InMemoryCache
            };

            return connection;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     由数据库连接串名称创建连接对象
        /// </summary>
        /// <param name="connectionStringName">数据库连接串名称</param>
        /// <returns></returns>
        private static DbConnection CreateConnectionWrapper(string connectionStringName)
        {
           
            var providerInvariantName = "System.Data.SqlClient";
            string connectionString = null;
            var connectionStringSetting = ConfigurationManager.ConnectionStrings[connectionStringName];
            if (connectionStringSetting != null)
            {
                providerInvariantName = connectionStringSetting.ProviderName;
                connectionString = connectionStringSetting.ConnectionString;
            }
            if (connectionString == null)
            {
                throw new Exception("名称为“" + connectionStringName + "”数据库连接串的ConnectionString值为空。");
            }
            var wrappedConnectionString = "wrappedProvider=" + providerInvariantName + ";" + connectionString;
            var connection = new EFCachingConnection
            {
                ConnectionString = wrappedConnectionString,
                CachingPolicy = CachingPolicy.CacheAll,
                Cache = InMemoryCache
            };

            return connection;
        }
 private static EFCachingConnection CreateCachingConnection(string connectionString, string providerName)
 {
     string wrapperConnectionString = string.Format(@"wrappedProvider={0};{1}", providerName, connectionString);
     EFCachingConnection connection =
         new EFCachingConnection
         {
             ConnectionString = wrapperConnectionString,
             CachingPolicy = CachingPolicy.CacheAll,
             Cache = InMemoryCache
         };
     return connection;
 }
 /// <summary>
 /// Initializes a new instance of the EFCachingTransaction class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="connection">The connection.</param>
 public EFCachingTransaction(DbTransaction transaction, EFCachingConnection connection)
     : base(transaction, connection)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the EFCachingTransaction class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="connection">The connection.</param>
 public EFCachingTransaction(DbTransaction transaction, EFCachingConnection connection)
     : base(transaction, connection)
 {
 }
Exemplo n.º 6
0
        /// <summary>
        /// Creates tracing connection which is a wrapper around native store connection.
        /// </summary>
        /// <returns>Instance of <see cref="EFCachingConnection"/> with enabled caching.</returns>
        private static EFCachingConnection CreateCachingConnection(string connectionName)
        {
            // Based on the tracing example at: http://jkowalski.com/2010/04/23/logging-sql-statements-in-entity-frameworkcode-first/
            var connection = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName];

            var efCachingconnection = new EFCachingConnection
            {
                ConnectionString = @"wrappedProvider=" + connection.ProviderName + ";" + connection.ConnectionString
            };

            return efCachingconnection;
        }