is there an ExecuteScalar in Dapper

后端 未结 3 571
醉梦人生
醉梦人生 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: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(sql, new { dateParameter = dateInQuestion });
    
                    return result;
                }
            }
            catch (Exception)
            {
                return dateInQuestion < DateTime.Now;
            }
        }
    

提交回复
热议问题