public object ExecuteScalar(string sql, params object[] parameters) { using (var cmd = CreateCommand()) { QueryBuilder.BuildCommand(cmd, sql, parameters); MicrOrmLogger.LogCommand(cmd); using (var rdr = cmd.ExecuteReader()) { if (!rdr.Read()) { return(null); } if (Convert.IsDBNull(0)) { return(null); } try { return(Convert.ChangeType(rdr[0], rdr.GetFieldType(0))); } catch (InvalidCastException) { return(null); } } } }
public void ExecuteNonQuery(string sql, params object[] parameters) { using (var cmd = CreateCommand()) { QueryBuilder.BuildCommand(cmd, sql, parameters); MicrOrmLogger.LogCommand(cmd); cmd.ExecuteNonQuery(); } }
public IEnumerable <IDictionary <string, object> > ExecuteReader(string sql, params object[] parameters) { using (var cmd = CreateCommand()) { QueryBuilder.BuildCommand(cmd, sql, parameters); MicrOrmLogger.LogCommand(cmd); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { yield return(FieldMapping.MapRowToDictionary(rdr)); } } } }