c# - bool type return rule in dapper -
i use dapper orm.so use 2 rules query & querysingle . query return list & querysingle return single object.
so,i want bool type.(actually wanted bool true or false record)
my query
public ienumerable<t> query<t>(string sqlstring) t : class { return this.conn.query<t>(sqlstring); } so,how can write bool type return ?
so, want bool type. (actually wanted bool true or false record)
you can write method this:
public bool getbooleanvalue(string sql) { return the_connection.query<bool>(sql).firstordefault(); } the beauty firstordefault when query returns empty row, dapper give false. suggested code work long query returns value can translated boolean data provider. in case of sql server get:
- true
getbooleanvalue("select 1"); - false
getbooleanvalue("select 0");
where 1 , 0 values table column of boolean type.
you can use code if want test if exists or group of values exists getbooleanvalue("select count(*) the_table the_column='some_filter'").
Comments
Post a Comment