/// <summary> /// the command should have the connections string set, doesnt have to be open but /// the string should be set. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> /// <param name="parameter"></param> /// <returns></returns> public static List <T> ToList <T>(this d.SqlClient.SqlCommand command, T parameter = null) where T : class, new() { List <T> ret = new List <T>(); try { if (command.IsConnectionOpen()) { setCommandParameters(parameter, command); using (var reader = command.ExecuteReader()) { var map = DataReaderMap.GetReaderMap(reader); while (reader.Read()) { T newObj = new T(); DataReaderMap.Set(reader, map, newObj); ret.Add(newObj); } } setOutputParameters(parameter, command); } } catch { throw; } finally { command.CloseConnection(); } return(ret); }
private static void executeReaderAndFillList <T>(d.SqlClient.SqlCommand command, List <T> ret) where T : class, IBattleAxe, new() { using (var reader = command.ExecuteReader()) { var map = DataReaderMap.GetReaderMap(reader); while (reader.Read()) { T newObj = new T(); DataReaderMap.Set(reader, map, newObj); ret.Add(newObj); } } }