is there an ExecuteScalar in Dapper

c# dapper

Question

it looks like there was an ExecuteScalar in Dapper...

http://code.google.com/p/dapper-dot-net/issues/attachmentText?id=22&aid=220000000&name=ExecuteScalar.cs&token=9e2fd8899022f507b140ffb883c60e34

Was ExecuteScalar renamed or removed?

Can this now be achieved with .Query or .Query<T>?

Accepted Answer

ExecuteScalar was just added in 1.28: https://www.nuget.org/packages/Dapper


Popular Answer

I was able to call ExecuteScalar< T > with version 1.42.0

    public Boolean BeforeToday(DateTime dateInQuestion)
    {
        try
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                String sql = @"SELECT CONVERT(bit, CASE WHEN getdate() > @dateParameter THEN 1 ELSE 0 END) AS BeforeToday";

                var result = conn.ExecuteScalar<Boolean>(sql, new { dateParameter = dateInQuestion });

                return result;
            }
        }
        catch (Exception)
        {
            return dateInQuestion < DateTime.Now;
        }
    }



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why