virtual public Inmueble ObtenerPorId(int id) { Inmueble i = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT Inmuebles.Id, PropietarioId, Direccion, Uso, Tipo, Ambientes, Precio, Inmuebles.Estado, " + $"p.Id, p.Nombre, p.Apellido, p.Dni, p.Telefono, p.Email, p.Clave, p.Estado" + $" FROM Inmuebles JOIN Propietarios AS p ON Inmuebles.PropietarioId = p.Id WHERE Inmuebles.Id = @id"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@id", SqlDbType.Int).Value = id; command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); if (reader.Read()) { i = new Inmueble { Id = reader.GetInt32(0), PropietarioId = reader.GetInt32(1), Direccion = reader.GetString(2), Uso = reader.GetString(3), Tipo = reader.GetString(4), Ambientes = reader.GetInt32(5), Precio = reader.GetInt32(6), Estado = reader.GetInt32(7), Propietario = new Propietario { Id = reader.GetInt32(8), Nombre = reader.GetString(9), Apellido = reader.GetString(10), Dni = reader.GetString(11), Telefono = reader.GetString(12), Email = reader.GetString(13), Clave = reader.GetString(14), } }; } connection.Close(); } } return(i); }