Beispiel #1
0
 /// <summary>
 /// Create an object with a SqlDataReader created from the SqlCommand
 /// passed. The SqlConnection object from that SqlCommand will be returned
 /// to the specified ConnectionPool when Dispose() is called on the enumerator.
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="connectionPool"></param>
 protected SqlEnumerator(SqlCommand cmd, PooledConnection pooledCon)
 {
     mConnection = cmd.Connection;
     mReader     = cmd.ExecuteReader();
     mPooledCon  = pooledCon;
     mCurrent    = null;
     mDisposed   = false;
 }
Beispiel #2
0
        public static SqlCommand CreateProc(string procName, PooledConnection pooledCon)
        {
            SqlCommand cmd = new SqlCommand(procName, pooledCon.Con);

            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.CommandTimeout = 60 * 60;
            return(cmd);
        }
Beispiel #3
0
        public static SqlDataAdapter CreateSelectAdapter(string procName, PooledConnection pooledCon)
        {
            SqlCommand     cmd     = SqlHelper.CreateProc(procName, pooledCon);
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = cmd;
            return(adapter);
        }
 public void ExecuteNonQuery(string procName, AddSqlParametersDelegate addParams)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc(procName, pooledCon))
         {
             addParams(cmd);
             cmd.ExecuteNonQuery();
         }
     }
 }
 public virtual void Delete(TPersistable entity)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc("dbo.Delete" + EntityName, pooledCon))
         {
             SqlHelper.AddParamInputId(cmd, EntityIdVarName, entity.GetIdValue());
             cmd.ExecuteNonQuery();
         }
     }
 }
 public virtual void Insert(TPersistable entity)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc("dbo.Insert" + EntityName, pooledCon))
         {
             SqlParameter param = SqlHelper.AddParamOutputId(cmd, EntityIdVarName);
             AddInsertUpdateParams(cmd, entity);
             cmd.ExecuteNonQuery();
             entity.SetIdValue((int)param.Value);
         }
     }
 }
 public List <TPersistable> Search(string procName, AddSqlParametersDelegate addParams)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlDataAdapter adapter = SqlHelper.CreateSelectAdapter(procName, pooledCon))
         {
             using (adapter.SelectCommand)
             {
                 addParams(adapter.SelectCommand);
                 return(CreateEntities(adapter));
             }
         }
     }
 }
 public virtual TPersistable Get(TId id)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlDataAdapter adapter = SqlHelper.CreateSelectAdapter(
                    "dbo.Get" + EntityName, pooledCon))
         {
             using (adapter.SelectCommand)
             {
                 SqlHelper.AddParamInputId(adapter.SelectCommand, EntityIdVarName, id.Value);
                 return(CreateEntities(adapter)[0]);
             }
         }
     }
 }