Ejemplo n.º 1
0
 public int GetTableEstimate(TableType tableType, int threshold)
 {
     TableEstimate tableEstimate;
     lock (estimate)
         if (!estimate.TryGetValue(tableType, out tableEstimate))
         {
             tableEstimate = new TableEstimate();
             estimate.Add(tableType, tableEstimate);
         }
     lock (tableEstimate)
     {
         if (tableEstimate.count == tableEstimate.threshold || tableEstimate.threshold < threshold)
         {
             DataProviderHelper helper = new DataProviderHelper(tableType);
             DbConnection connection = DataProviderHelper.CreateDbConnection(tableType.DataSource.ProviderInvariantName);
             connection.ConnectionString = tableType.DataSource.ConnectionString;
             connection.Open();
             try
             {
                 DbCommand command = connection.CreateCommand();
                 command.CommandText = helper.GetEstimateRowCountQuery(tableType.ToString(helper), threshold);
                 tableEstimate.count = Convert.ToInt32(command.ExecuteScalar());
                 tableEstimate.threshold = threshold;
             }
             finally
             {
                 connection.Close();
             }
         }
         return tableEstimate.count;
     }
 }