public async static Task <List <T> > Map <T>(this IQueryMapper query, Func <DbDataReader, T> mapper) { var res = new List <T>(); await query.Map(reader => { res.Add(mapper(reader)); }); return(res); }
public IEnumerable <LogIn> GetLogInsWhichIdIsBetween(long begin, long end) { const string kExecute = @" select id ,agente ,dtini ,dtfim ,filas ,1000 as tipo_id ,dtfim >= dtini as loggedout from login where id between @begin and @end order by id asc "; var mysql_connection_provider = new MySqlConnectionProvider( "Data Source=192.168.203.207;Initial Catalog=acaconb1;User ID=callflex;Password=$callflex$;"); var mysql_executor = new MySqlQueryExecutor(mysql_connection_provider); /*using ( * var conn = * new MySqlConnection( * "Data Source=192.168.203.207;Initial Catalog=acaconb1;User ID=callflex;Password=$callflex$;") * ) * using (var builder = new CommandBuilder(conn)) { * IDbCommand cmd = * builder * .AddParameter("@begin", begin) * .AddParameter("@end", end) * .SetText(kExecute) * .Build(); * conn.Open(); * using (IDataReader reader = cmd.ExecuteReader()) { * int[] ordinals = new int[] { * reader.GetOrdinal("id"), reader.GetOrdinal("tipo_id"), * reader.GetOrdinal("dtini"), reader.GetOrdinal("agente"), * reader.GetOrdinal("dtfim"), reader.GetOrdinal("filas"), * reader.GetOrdinal("loggedout") * }; * //return Map(reader); * } * conn.Close(); * }*/ using (IQueryMapper <LogIn> mapper = mysql_executor .ExecuteQuery(kExecute, LogInDto, builder => builder .AddParameter("@begin", begin) .AddParameter("@end", end))) { IEnumerable <LogIn> logins = mapper.Map(false); //IEnumerable<LogIn> logins = Map(((QueryMapper<LogIn>) mapper).Reader); return(logins); } //return Enumerable.Empty<LogIn>(); }
public IEnumerable <long> GetSeriesIds(string name, int hash, int count) { using (IQueryMapper <long> mapper = sql_query_executor_ .ExecuteQuery(schema_ + ".mtc_get_id_of_serie", Mappers.Long, builder => builder .AddParameter("@name", name) .AddParameter("@hash", hash) .AddParameter("@tags_count", count))) { return(mapper.Map(false)); } }
/// <summary> /// Returns first row mapped as object T, or default value of T if no results are returned. /// </summary> /// <typeparam name="T">Generic type of the objects that wil be returned.</typeparam> /// <param name="query">The IQueryMapper object.</param> /// <param name="mapper">Mapper function that will convert DbDatareader to T</param> /// <returns>First object in the result set of default(T).</returns> public async static Task <T> FirstOrDefault <T>(this IQueryMapper query, Func <DbDataReader, T> mapper) where T : new() { var res = new T(); bool isNull = true; await query.Map(reader => { res = mapper(reader); isNull = false; }); if (isNull) { return(default(T)); } else { return(res); } }
public void should() { const string kExecute = @" select distinct hc.cod_hist_cli ,hc.cod_dev ,cast(t.cod_cred as varchar) as cod_cred ,hc.data_cad ,isnull(hc.dt_agen_hist, hc.data_cad) as dt_agen_hist ,hc.usuario_cad ,hc.cod_ocor ,hc.data_up ,cast(case when hc.dt_agen_hist is null then 0 else 1 end as bit) as agendado from historicos_clientes hc inner join historicos_clientes_titulos hct on hct.cod_hist_cli = hc.cod_hist_cli inner join titulos t with(nolock) on t.cod_tit = hct.cod_tit where hc.cod_hist_cli between @min_cod_hist_cli and @max_cod_hist_cli order by cod_hist_cli asc"; var map = new DataReaderMapperBuilder <CobEventDto>() .Map(x => x.AgentId, "usuario_cad") .Map(x => x.Segment, "cod_cred") .Map(x => x.Date, "data_cad") .Map(x => x.DebtorId, "cod_dev") .Map(x => x.ExpiryDate, "dt_agen_hist") .Map(x => x.Id, "cod_hist_cli", typeof(int)) .Map(x => x.TypeId, "cod_ocor") .Map(x => x.IsScheduled, "agendado") .Map(x => x.RecordDate, "data_up") .Build(); var sql_connection_provider = new SqlConnectionProvider(@"Data Source=192.168.203.9\itau;Initial Catalog=cobsystems;User ID=nohros;Password=Noors03;"); var sql_executor = new SqlQueryExecutor(sql_connection_provider, CommandType.Text); using (IQueryMapper <CobEventDto> mapper = sql_executor .ExecuteQuery(kExecute, () => map, builder => builder .AddParameter("@min_cod_hist_cli", 631583866) .AddParameter("@max_cod_hist_cli", 631588866))) { Dynamics_.AssemblyBuilder.Save("nohros.tests.dll"); mapper.Map(false); } }
public static Task ExecuteReader(this IQueryMapper mapper, SqlCommand cmd, Action <DbDataReader> callback) { return(mapper.Map(cmd, callback)); }
public static Task Map(this IQueryMapper mapper, string sql, Action <DbDataReader> callback) { var cmd = new SqlCommand(sql); return(mapper.Map(cmd, callback)); }
public static Task ExecuteReader(this IQueryMapper mapper, string sql, Action <DbDataReader> callback) { return(mapper.Map(sql, callback)); }