public Student GetById(int id) { string selectStudents = $"SELECT * FROM Student WHERE Id = {id}"; _db.Command.CommandText = selectStudents; _db.Connection.Open(); var result = _db.Command.ExecuteReader(); List<Student> students = new List<Student>(); while (result.Read()) { students.Add(StudentMapper.Map(result)); } _db.Connection.Close(); return students.FirstOrDefault(); }
public List<Student> GetStudents() { string selectStudents = $"SELECT * FROM Student"; _db.Command.CommandText = selectStudents; _db.Connection.Open(); var result = _db.Command.ExecuteReader(); List<Student> students = new List<Student>(); while (result.Read()) { var student = StudentMapper.Map(result); //var student_ = StudentMapper.Map<Student>(result); students.Add(student); } _db.Connection.Close(); return students; }