public static IEnumerable <T> RawQuery <T>(this ScraperContext ctx, string sql, Func <System.Data.IDataReader, T> map, params Tuple <string, string>[] parameters)
        {
            using (var command = ctx.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = sql;
                command.CommandType = CommandType.Text;

                foreach (var param in parameters)
                {
                    var p = command.CreateParameter();
                    p.DbType        = DbType.String;
                    p.ParameterName = param.Item1;
                    p.Value         = param.Item2;
                    command.Parameters.Add(p);
                }

                ctx.Database.OpenConnection();

                using (var result = command.ExecuteReader())
                {
                    var entities = new List <T>();
                    while (result.Read())
                    {
                        var entity = map(result);
                        entities.Add(entity);
                    }

                    return(entities);
                }
            }
        }
Esempio n. 2
0
 public ArticlesRepository(ScraperContext ctx)
 {
     _ctx = ctx ?? throw new ArgumentNullException(nameof(ctx));
 }