GraphView.GraphViewCommand.ExecuteReader C# (CSharp) Method

ExecuteReader() public method

public ExecuteReader ( ) : System.Data.SqlClient.SqlDataReader
return System.Data.SqlClient.SqlDataReader
        public SqlDataReader ExecuteReader()
        {
            try
            {
                if (CommandType == CommandType.StoredProcedure)
                {
                    if (Tx != null)
                    {
                        Command.Transaction = Tx;
                    }
                    Command.CommandText = CommandText;
                    return Command.ExecuteReader();
                }

                var sr = new StringReader(CommandText);
                var parser = new GraphViewParser();
                IList<ParseError> errors;
                var script = parser.Parse(sr, out errors) as WSqlScript;
                if (errors.Count > 0)
                    throw new SyntaxErrorException(errors);

                if (Tx == null)
                {
                    var translationConnection = GraphViewConnection.TranslationConnection;

                    using (SqlTransaction translationTx = translationConnection.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
                    {
                        var visitor = new TranslateMatchClauseVisitor(translationTx);
                        visitor.Invoke(script);

                        // Executes translated SQL
                        Command.CommandText = script.ToString();
            #if DEBUG
                        // For debugging
                        OutputResult(CommandText, Command.CommandText);
                        //throw new GraphViewException("No Execution");
            #endif
                        var reader = Command.ExecuteReader();
                        translationTx.Commit();
                        return reader;
                    }
                }
                else
                {
                    var visitor = new TranslateMatchClauseVisitor(Tx);
                    visitor.Invoke(script);
                    // Executes translated SQL
                    Command.CommandText = script.ToString();
            #if DEBUG
                    // For debugging
                    OutputResult(CommandText, Command.CommandText);
                    //throw new GraphViewException("No Execution");
            #endif
                    var reader = Command.ExecuteReader();
                    return reader;
                }
            }
            catch (SqlException e)
            {
                throw new SqlExecutionException("An error occurred when executing the query", e);
            }
        }

Usage Example

        public SqlDataReader ExecuteReader(string queryString, int timeout = 0 )
        {
            using (var command = new GraphViewCommand(queryString, this))
            {
                command.CommandTimeOut = timeout;
                return command.ExecuteReader();
            }

        }