Exemple #1
0
        //With SqlDependency
        public GenericType EncapsulatedRead <GenericType>(object ParametersObject, string ProcedureName, int RowIndex, bool AllowCache)
        {
            if (AllowCache)
            {
                CacheBase cb        = new CacheBase();
                object    cachedObj = cb[ParametersObject];

                if (cachedObj != null)
                {
                    return((GenericType)cachedObj);
                }
                else
                {
                    GenericType ret = (GenericType)System.Activator.CreateInstance(typeof(GenericType));
                    ExtractObject <GenericType>(ReturnDataTable(ParametersObject, ProcedureName), ret, RowIndex);
                    SqlDependencyExpiration dependency = GetSQLDependency(ParametersObject, ProcedureName);
                    return(cb.Add <GenericType>(ParametersObject, ret, dependency));
                }
            }
            else
            {
                GenericType ret = (GenericType)System.Activator.CreateInstance(typeof(GenericType));
                ExtractObject <GenericType>(ReturnDataTable(ParametersObject, ProcedureName), ret, RowIndex);
                return(ret);
            }
        }
Exemple #2
0
 private SqlDependencyExpiration GetSQLDependency(object ParametersObject, string ProcedureName)
 {
     using (SqlConnection conn = new SqlConnection(Conn))
     {
         SqlCommand command = new SqlCommand(ProcedureName, conn);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddRange(BindParameters(ParametersObject, ProcedureName));
         conn.Open();
         SqlDependencyExpiration dependency = new SqlDependencyExpiration(command);
         command.ExecuteNonQuery();
         return(dependency);
     }
 }