I have this code which returns the correct data from one table. But I have related data in other tables using INNER JOIN. So my question is how to code to return this in the result?
IList<Schedule> GetCurrentValues()
{
var result = new List<Schedule>();
using (var sqlConnection = new SqlConnection(_configuration["DefaultConnection"]))
{
sqlConnection.Open();
using (var command = sqlConnection.CreateCommand())
{
command.CommandText = "SELECT Schedules.AppointmentHeading, Schedules.AppointmentDateStart, Schedules.AppointmentDateEnd, Bookers.Email, Rooms.Id AS Expr3, Rooms.Name " +
"FROM Schedules " +
"INNER JOIN Rooms ON Schedules.RoomId = Rooms.Id " +
"INNER JOIN Bookers ON Schedules.BookerId = Bookers.Id";
command.CommandType = CommandType.Text;
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
// How should I code so I also get Bookers.Email and Room.Name?
}
}
}
}
}
return result;
}