public void Generate() { Logger = new BasicLogger(Options.Verbose); try { GenerateHelper(); } catch (Exception e) { Logger.LogError(e, "Exception thrown in generate method"); } if (Logger.HasErrors) { using (var sw = new StringWriter()) { Logger.Output(sw); throw new Exception(sw.ToString()); } } }
public List <T> ReadPocos <T>(string selectQuery) where T : new() { var returnPocos = new List <T>(); try { using (var connection = _providerFactory.CreateConnection()) { connection.ConnectionString = _connectionString; connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = selectQuery; using (var reader = command.ExecuteReader()) { if (reader != null && reader.FieldCount > 0) { // change this to an array. No reason why not to. var columnNames = new List <string>(); for (var col = 0; col < reader.FieldCount; col++) { columnNames.Add(reader.GetName(col)); } while (reader.Read()) { var poco = new T(); foreach (var columnName in columnNames) { object baseValue = reader.GetValue(reader.GetOrdinal(columnName)); if (baseValue == DBNull.Value) { // need to implement null pattern } else { // populate poco property with value from cell poco.GetType().GetProperty(columnName).SetValue(poco, baseValue); } } returnPocos.Add(poco); } } else { return(returnPocos); } } } } } catch (Exception e) { // log the exception _basicLogger.LogError("Odbc Command Select Query Failed Due To Error: " + e.Message + Environment.NewLine + "Select Query was:" + Environment.NewLine + selectQuery); } return(returnPocos); }