title: reading from IDbCommand using an inherited custom IDataReader
body: <p>I have made a custom class inherits <code>IDataReader</code> and have successfully
  implemented a custom ServerWriter <code>sqlBulkCopy</code> with the custom class which uses a C# object instead of <code>DataTable</code>.</p>
  
  <p>That proved to be a more efficient approach as I suspected.</p>
  
  <p>Now I am trying to <code>Read</code> and I have some problems </p>
  
  <p>This is the <code>IDataReader</code>:</p>
  
  <pre><code>// get Server Data Table Object IDataReader
  public class GetSDTOIDataReaderM : IDataReader
  {
     //private IEnumerator&lt;MyTestObject&gt; enumerator = null;
  
     public MySqlDbTableObject.Raw.SqlDbTableM propSqlTbl { get; set; }
  
     // implementing relevant GetValue(), filedCount() and Read()
     // this is how I did with WriteToServer
     public bool Read()
     {
         return ++this.ReaderRowsCount &lt; this.propSqlTbl.Table.ElementAt(0).Row.Count;
     }
  }
  </code></pre>
  
  <p>The object is mapped exactly as its corresponded SqlTable.</p>
  
  <p>Setting an <code>SqlCommand</code> to ExecuteReader() on my custom IDataReader did not work so I have tried with
  <code>IDbCommand</code> which then it did compile, but still when trying to read 
  I get an error:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to
    type 'GetSDTOIDataReaderM'</p>
  </blockquote>
  
  <pre><code>this.propComunicator.AsGetSDTOCom().SqlCmd.Connection.Open();
  //this is the line of the error
  using (this.propComunicator.AsGetSDTOCom().SDTOIDataReader = (Raw.Comunicator.Raw.GetSDTOIDataReaderM)this.propComunicator.AsGetSDTOCom().SqlCmd.ExecuteReader())
  {
  
  }
  </code></pre>
  
  <p>As write to server it did work, <strong>how can I implement it correctly with <code>Read</code>?</strong></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>A little more about my modules</p>
  
  <pre><code>public class TransManSF
  {
      public enum CommunicatorTypeS { Reader, Adapter, GetSDTOReaderA, SqlBcpyIDataReaderM };
      public enum DbIntreactorTypeS { TableObject, TableRowObject, Sproc, SqlCmd };
      public enum SqlCmdActionS { NotSet, SELECT, INSERT, UPDATE, DROP };
      public enum SqlCmdStrSelModeS { Single, RecentEfected, count, All, Top10, Top100, Top1000 };
      public enum SqlCmdStrSelOrderByS { NotSet = 0, Asc = 1, Desc = 2 };
      public enum SqlCmdStrSetterModeS { Single, Multi};
      public enum STDOTypeS { NotSet, ServerWriter, ServerTableGetter, ServerBiDerctional }
      public enum SprocTypeS { Sproc, TvPSrpoc }
      public enum TransExecActionTypeS { WriteToServer, GetTable }
  }
  
  public static TransMan.Raw.ComunicatorCLF.BulkCopyComSCL AsBulkCopyCom(this TransMan.Raw.ComunicatorCLF.ComunicatorM SelfCom)
  {
      return (TransMan.Raw.ComunicatorCLF.BulkCopyComSCL)SelfCom;
  }
  
  virtual public void ExecuteTransaction(AppMods.DataBase.TransManSF.TransExecActionTypeS parSelectedTransType, TransManSF.SqlCmdStrSelOrderByS parExecOrderByS, int OrderByOrdinal = 0)
  {
      if (parSelectedTransType == AppMods.DataBase.TransManSF.TransExecActionTypeS.WriteToServer)
          using (this.propComunicator.AsBulkCopyCom().Conn)
          {
              this.propComunicator.AsBulkCopyCom().Conn.Open();
              using (var IDRdrServerWriter = this.propComunicator.AsBulkCopyCom().ServerWriter)
              {
                  var Eng = this.propExecuter.AsBulkCopyExec().Engine;
                  Eng.BulkCopyTimeout = 240;
                  Eng.WriteToServer(IDRdrServerWriter);
  
              }
              this.propComunicator.AsBulkCopyCom().Conn.Close();
          }
      else if (parSelectedTransType == AppMods.DataBase.TransManSF.TransExecActionTypeS.GetTable)
      {
          var DreaderCom = this.propComunicator.AsDReaderCom();
          using (DreaderCom.SqlCmd.Connection)
          {
              DreaderCom.SqlCmd.Connection.Open();
              using (DreaderCom.Driver = DreaderCom.SqlCmd.ExecuteReader())
              {
                  if (DreaderCom.Driver.HasRows) while (DreaderCom.Driver.Read())
                      {
                          for (int i = 0; i &lt; DreaderCom.Driver.FieldCount; i++)
                          {
                              var CurRdrColumn = DreaderCom.Driver.GetValue(i);
                              this.Table[i, 0] = CurRdrColumn;
                          }
                      }
              }
              DreaderCom.SqlCmd.Connection.Close();
          }                           
      }
  }
  
  
  public struct customComConfgBulkCopyA
  {
        public TransManSF.CommunicatorTypeS ComType;
        public customComConfgBulkCopyA(TransManSF.CommunicatorTypeS ctrComType = TransManSF.CommunicatorTypeS.SqlBcpyIDataReaderM)
        {
            this.ComType = ctrComType;
        }
  }
  public sealed class BulkCopyComSCL :CustomComA
  {
       public new Configurations.comunicator.customComConfgBulkCopyA Meta;
       public SqlConnection Conn { get; set; }
       public Raw.SqlBcpyIDataReaderM ServerWriter { get; set; }
  }
  
  public class SqlDbTableM : SqlDB1stTransA
  {
       virtual public DbSchema.Raw.TableDictionaryA TableDict { get; set; }
       public virtual new TransMan.Raw.Configurations.SDB1stTransConfgF.SDTOMetaA Meta { get; set; }
       virtual public Raw.ColumnSetsCollM Table { get; set; }
       public override TransMan.Raw.ComunicatorCLF.ComunicatorM propComunicator
       {
           get
           {
                return base.propComunicator;
           }
           set
           {
                base.propComunicator = value;
           }
       }
       public override TransMan.Raw.Executers.ExecuterM propExecuter
       {
           get
           {
               return base.propExecuter;
           }
           set
           {
               base.propExecuter = value;
           }
       }
       public SqlDbTableM(TransManSF.STDOTypeS ctrTransType)
              : base(TransManSF.DbIntreactorTypeS.TableObject) { }
  }
  
  public sealed class GetSDTOComSCL : CustomComA
  {
      public new Configurations.comunicator.customComConfgGetSDTOReaderA Meta;
      public new IDbCommand SqlCmd;
      public Raw.GetSDTOIDataReaderM SDTOIDataReader { get; set; }
  }
  </code></pre>