public string SerializeCommand(RemotingDbCommand command)
        {
            var data = new RemotingDbCommandData()
            {
                CommandText = command.CommandText,
                Parameters  = command.Parameters.OfType <RemotingDbParameter>().Select(f => new RemotingDbParameterData()
                {
                    ParameterName = f.ParameterName,
                    Value         = f.Value,
                    DbType        = f.DbType,
                    Direction     = f.Direction == 0 ? ParameterDirection.Input : f.Direction,
                    IsNullable    = f.IsNullable,
                    Precision     = f.Precision,
                    Scale         = f.Scale,
                    Size          = f.Size,
                    SourceColumn  = f.SourceColumn,
                    SourceVersion = f.SourceVersion == 0 ? DataRowVersion.Default : f.SourceVersion
                }).ToArray(),
                CommandTimeout = command.CommandTimeout,
                CommandType    = command.CommandType == 0 ? CommandType.Text : command.CommandType,
            };

            using (var textWriter = new MemoryStream())
            {
                RemotingCommandSerializer.WriteObject(textWriter, data);
                return(Encoding.Default.GetString(textWriter.ToArray()));
            }
        }
        /// <inheritdoc />
        public IDbCommand CreateCommand(string strSql, IDbConnection conn, params IDataParameter[] fields)
        {
            var remotingDbCommand = new RemotingDbCommand(this)
            {
                CommandText = strSql,
                Connection  = conn
            };

            foreach (var dataParameter in fields)
            {
                remotingDbCommand.Parameters.Add(dataParameter);
            }
            return(remotingDbCommand);
        }
 public override object ExecuteScalar(RemotingDbCommand command)
 {
     return(ExecuteScalar(SerializeCommand(command),
                          GetOrThrowConnectionId(command.Connection as RemotingDbConnection),
                          TryGetTransactionId(command.Transaction as RemoteDbTransaction)));
 }
 public override IEnumerable <IEnumerable <IDataRecord> > EnumerateCommand(RemotingDbCommand command, CommandBehavior behavior, out int recordsAffected)
 {
     return(ExecuteCommand(SerializeCommand(command),
                           GetOrThrowConnectionId(command.Connection as RemotingDbConnection),
                           TryGetTransactionId(command.Transaction as RemoteDbTransaction), out recordsAffected));
 }
 /// <summary>
 ///		Should execute the query an return a IDataReader that contains the result.
 ///		You can overwrite the EnumerateDataRecord method to use an inbuild IDataReader
 /// </summary>
 /// <param name="command"></param>
 /// <param name="behavior"></param>
 /// <returns></returns>
 public virtual IDataReader ExecuteReader(RemotingDbCommand command, CommandBehavior behavior)
 {
     return(new VirtualDataReader(EnumerateCommand(command, behavior, out var records), Config, records));
 }
 /// <summary>
 ///		You can overwrite this method to return multiple sets of IDataRecords.
 ///		If you only got objects you can use the ObjectDataRecord to wrap them into IDataRecords
 /// </summary>
 /// <param name="command"></param>
 /// <param name="behavior"></param>
 /// <param name="recordsAffected"></param>
 /// <returns></returns>
 public virtual IEnumerable <IEnumerable <IDataRecord> > EnumerateCommand(RemotingDbCommand command, CommandBehavior behavior, out int recordsAffected)
 {
     throw new NotImplementedException("Please ether overwrite the ExecuteReader function or the EnumerateCommand function.");
 }
 /// <summary>
 ///		Should execute the query and return a single result
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public abstract object ExecuteScalar(RemotingDbCommand command);
 /// <summary>
 ///		Should execute the Query and return an value int
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public abstract int ExecuteQuery(RemotingDbCommand command);