自動キャッシュ無効化によるLinq2Sqlテーブルキャッシング

キャッシュに関するこのトピックの続きとして、あまり大きくないテーブルをキャッシュするための部分的に強化された独自のソリューションを提供したいと思います。 これを行うには、単に新しい拡張メソッドを作成します。
Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  1. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  2. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  3. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  4. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  5. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  6. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  7. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  8. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  9. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  10. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  11. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  12. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  13. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  14. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  15. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  16. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  17. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  18. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  19. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  20. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  21. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  22. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  23. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  24. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  25. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  26. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  27. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  28. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  29. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  30. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  31. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  32. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  33. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  34. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  35. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  36. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  37. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  38. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  39. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  40. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  41. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  42. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  43. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  44. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  45. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  46. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  47. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  48. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  49. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  50. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  51. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  52. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  53. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  54. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  55. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  56. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  57. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  58. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  59. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  60. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  61. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  62. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  63. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  64. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  65. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  66. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  67. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  68. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  69. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  70. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  71. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  72. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  73. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }
  74. Copy Source | Copy HTML public static class CachingHelper { /// <summary> /// /// </summary> private static string conString = System.Configuration.ConfigurationManager. ConnectionStrings [ "pltfrmDBConnectionString" ].ConnectionString; /// <summary> /// Cache instance object /// </summary> private static volatile Cache cache = HttpContext.Current.Cache; /// <summary> /// Object for proper locking of cache additions/removals /// </summary> private static object syncRoot = new object (); /// <summary> /// /// </summary> /// <param name="query"> </param> /// <typeparam name="T"> </typeparam> /// <returns> T</returns> public static T [] LinqCache< T >( this Table< T > query) where T : class { var tableName = query.Context.Mapping.GetTable( typeof ( T )).TableName; var result = cache[tableName] as T []; if (result != null ) { return result; } var trop = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; var req = TransactionScopeOption.Required; if (Transaction.Current == null || Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted) { req = TransactionScopeOption.RequiresNew; } using ( var ts = new TransactionScope (req, trop)) { using ( var cn = new SqlConnection (conString)) { try { cn.Open(); var cmdText = query.Context.GetCommand(query).CommandText; var cmd = new SqlCommand (cmdText, cn) { NotificationAutoEnlist = true , Notification = null , CommandType = CommandType.Text }; foreach ( DbParameter dbp in query.Context.GetCommand(query).Parameters) { cmd.Parameters.Add( new SqlParameter (dbp.ParameterName, dbp.Value)); } var dependency = new SqlCacheDependency (cmd); cmd.ExecuteNonQuery(); result = query.ToArray(); cache.Insert(tableName, result, dependency); } catch (SqlException e) { if (e.Number == 4060 ) { throw new AuthenticationException ( " " ); } throw ; } } ts.Complete(); } return result; } }


使用方法は、梨を砲撃するのと同じくらい簡単です。
1)Global.asaxに追加
Copy Source | Copy HTML
  1. /// <summary>
  2. ///アプリケーション開始イベント
  3. /// </ summary>
  4. /// <param name = "sender">
  5. ///呼び出し元
  6. /// </ param>
  7. /// <param name = "e">
  8. ///イベント引数
  9. /// </ param>
  10. protected void Application_Start( オブジェクト送信者、 EventArgs e)
  11. {
  12. SqlDependency.Start(ConfigurationManager.ConnectionStrings [ "pltfrmDBConnectionString" ] .ConnectionString);
  13. }
  14. /// <summary>
  15. ///アプリケーション終了イベント
  16. /// </ summary>
  17. /// <param name = "sender">
  18. ///呼び出し元
  19. /// </ param>
  20. /// <param name = "e">
  21. ///イベント引数
  22. /// </ param>
  23. protected void Application_End( オブジェクト送信者、 EventArgs e)
  24. {
  25. SqlDependency.Stop(ConfigurationManager.ConnectionStrings [ "pltfrmDBConnectionString" ] .ConnectionString);
  26. }

2)アプリケーションでの使用:

Copy Source | Copy HTML
  1. var db = new SomeContext ();
  2. var cached = db.SomeTable.LinqCache()。Where(a => ab == "qwe" );

PSこの方法が機能するには、SQLサーバーブローカーが有効になっている必要があります
PPSトランザクションはオプションです;これらは現在のプロジェクトからのコードの一部です:)


Source: https://habr.com/ru/post/J61655/


All Articles