private EntityCollection GetEntitiesFromSql(PluginExecutionContext context, GenericMapper mapper, string sql, int pageSize, int pageNumber) { context.Trace($"SQL: {sql}"); EntityCollection collection = new EntityCollection(); using (SqlConnection sqlConnection = new SqlConnection(context.GetSqlConnectionString())) { SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection); DataSet dataSet = new DataSet(); sqlConnection.Open(); sqlDataAdapter.Fill(dataSet, "SqlData"); sqlConnection.Close(); context.Trace($"Records Retrieved: {dataSet.Tables[0].Rows.Count}", Array.Empty <object>()); collection = mapper.CreateEntities(dataSet, pageSize, pageNumber); } return(collection); }