Variational techniques in general relativity: a metric-affine approach to Kaluza's theory