DbCommand - ExecuteExpandoObjects

Enumerates execute expando objects in this collection.

Try it

public static void Main()
{
    string sql = "SELECT 1 AS IntColumn, 'FizzBuzz' AS StringColumn UNION SELECT 2, 'BuzzBuzz'";

    using (var conn = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
    {
        conn.Open();
        using (DbCommand command = conn.CreateCommand())
        {
            command.CommandText = sql;
			
			//C# Extension Method: DbCommand - ExecuteExpandoObjects
            List<dynamic> list = command.ExecuteExpandoObjects().ToList();

            Console.WriteLine(list[0].IntColumn);
            Console.WriteLine(list[0].StringColumn);
            Console.WriteLine(list[1].IntColumn);
            Console.WriteLine(list[1].StringColumn);
        }
    }
}

View Source
using System.Collections.Generic;
using System.Data;
using System.Data.Common;

public static partial class Extensions
{
    /// <summary>
    ///     Enumerates execute expando objects in this collection.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>
    ///     An enumerator that allows foreach to be used to process execute expando objects in this collection.
    /// </returns>
    public static IEnumerable<dynamic> ExecuteExpandoObjects(this DbCommand @this)
    {
        using (IDataReader reader = @this.ExecuteReader())
        {
            return reader.ToExpandoObjects();
        }
    }
}