is there an ExecuteScalar in Dapper

后端 未结 3 548
醉梦人生
醉梦人生 2021-01-03 19:38

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

相关标签:
3条回答
  • 2021-01-03 20:05

    In version 1.50.4 I was able to call connection.QuerySingle<int>(query,params)

    0 讨论(0)
  • 2021-01-03 20:14

    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;
            }
        }
    
    0 讨论(0)
  • 2021-01-03 20:21

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

    0 讨论(0)
提交回复
热议问题