Why can we apply the $E=hf$ equation for electrons? So in my textbook, it states that the $E=hf$ equation applies to electrons, and all particles, not just photons. 
But in order to prove this, wouldn't these particles need to have zero mass, to satisfy $E=pc$ from Einstein's equation? 
In Einstein's theory of relativity $E^2= p^2c^2 + m^2c^4$, we get $E=pc$ because we consider the mass to be zero. 
For $E=hf$ to work for other particles, don't we need to assume electrons have zero rest mass?
 A: The quantum relationship between energy $E$ and angular frequency $\omega$ has nothing to do with the classical relationship between energy and momentum $\mathbf p$. Wavenumber $\mathbf k$ has a similar quantum relationship to momentum.
The relationships are
$$E=\hbar\omega,$$
$$\mathbf p=\hbar\mathbf k,$$
and
$$E^2-(\mathbf pc)^2=(mc^2)^2.$$
Thus the relationship between angular frequency and wavenumber is
$$\omega^2-(\mathbf kc)^2=\left(\frac{mc^2}{\hbar}\right)^2.$$
When $m=0$, as for photons, these simplify to
$$E=pc$$
and
$$\omega=kc.$$
If you prefer to think in terms of regular frequency $f$ rather than angular frequency, and wavelength $\lambda$ instead of wavenumber, use
$$\omega=2\pi f$$
and
$$k=\frac{2\pi}{\lambda}.$$
You’ll get
$$f^2-\left(\frac{c}{\lambda}\right)^2=\left(\frac{mc^2}{h}\right)^2.$$
A: The formula $E=hf$ holds for both. For photons we also have $E=pc$ and then $p=h/\lambda=\hbar k$: this last formula for momentum and wavelength/wavenumber, it turns out, also holds for both electrons and photons.
The former relations give a linear dispersion $\omega(k)= c k$ for photons; when you transition to nonrelativistic electrons you instead get a quadratic dispersion relationship $\omega(k)=\hbar k^2/(2m)$ from $E=p^2/(2m).$ 
It is easy to get confused about that: does this mean a wave speed of $\omega/k=p/(2m)$ and isn't that wrong? Well, not quite: that is a formula for a pure plane wave whose motion would be unobservable to us in the quantum theory... a Gaussian wave packet (a localized particle in QM) actually travels at the group velocity $d\omega/dk=p/m$ which makes perfect sense here.
A: The concept that light carries momentum and the equation $p= \frac{E}{c}$ is totally a classical theory and preceeds it's formualtion from the Special Relativity and Planck-Einstein Relation of photons. The derivation of $p=\frac{E}{c}$ goes like this (Feynman's derivation, Volume 1, Chapter 34, Section 34-9)   
Imagine that we have an electromagnetic wave or light propagating in $x$direction, and $\mathbf{E}$ is oscillating in [itex]z[/itex] direction and $ \mathbf{B}$  in $y$ direction. The picture looks something like this

Now, if there exists a charged particle $ q $ on the xx axis at rest, then our B field can't do anything, but the electric field E will pull it upwards and as soon as it starts moving the magnetic field B comes into action and it goes like this $$ \mathbf{F_{mag}} = q (\mathbf{v} \times \mathbf{B}) $$ Since, E is gonna cause a velocity in [itex] z [/itex] direction i.e. perpendicular to magnetic field B , therefore $$ F_{mag} = q~v~B$$
$$ F_{mag} = q~v~\frac{E}{c}$$
$$F_{mag} = v~\frac{(qE)}{c}$$
$$ F_{mag} = \frac{F_{electric}~v}{c}$$
$$ F_{mag} = \frac{dW_{electric}/dt}{c}$$ 
$$ \frac{dp}{dt} = \frac{1}{c} ~ \frac{dW}{dt}$$
$$ dp = \frac{dW}{c} $$
$$ p= \frac{E}{c}$$ . 
So, this is the equation of light's momentum related to its energy.  
There was a problem in the 19th century regarding the radiation emitted by black bodies, you can read about it [here][2.]. Stephen Hawking writes in A brief History of Time 

Lord Rayleigh and Sir James Jeans suggested that a hot object, or body, such as a star, must radiate energy at an infinite rate. According to the laws we believed at that time, a hot body ought to give off electromagnetic waves (such as radio waves, visible light or X-rays) equally at all frequencies. For example, a hot body should radiate the same amount of energy in waves with frequencies between one and two million million waves a second as in waves with frequencies between two and three million million waves a second. Now since the number of waves a second is unlimited, this would mean that total energy radiated would be infinite.
  In order to avoid this obviously ridiculous result, the German Scientist Max Planck suggested in 1900 that light, X-rays, and other waves could not be emitted at an arbitrary rate, but only in certain packets that he called quanta.  

And in this way came the famous equation $$ E = hf$$.  
In 1905, Albert Einstein explained the phenomenon of Photoelectric Effect and postulated that light behaves like particles and the light particles, called photons have energy $$ E= hf$$ where $h$ is the Planck's Constant and f is the frequency of light wave to which photon belongs. You, see that the energy of photon is not the classical kinetic energy $1/2~m~v^2$, the energy of the light particle is determined by its wave character.  
To account for the validity of all these discoveries, Einstein gave the famous equation $$ E = \frac{m_0~c^2}{\sqrt{1-v^2/c^2}}$$ and if we do some maths, like this $$ E \times \sqrt{1-v^2/c^2} = m_0 c^2$$
and putting $v=c$ for the photons, we would find $ m_0 = 0$. Well, the equation that you have given was of Dirac's, not Einstein's. And Dirac wrote it in that form only to ensure that the preceding discoveries should not be violated. As you have done it very rightly that for zero rest mass the equation reduces to $E=pc$. But this was only done to make sure that classical derivation of the momentum of light should come out the way it did.  
The famous French physicist Louis Victor de Broglie reasoned that nature was symmetrical and that the two basic physical entities - matter and energy, must have symmetrical character. If radiation shows dual aspects, so should matter. So, he proposed that matter waves should have energy associated with them by the same Planck-Einstein Relation $$ E = hf$$ and their momentum should also follow the same equation, that is $$ p= \frac{E}{v}$$ and with some little mathematical arrangements $$ p= \frac{hf}{v}$$
$$ p = \frac{h}{\lambda}$$
$$\lambda = \frac{h}{p}$$ is the De Broglie's wavelength.  
So, $E=hf$ has nothing to do with zero rest mass, the zero rest mass of photons is an intentional consequence of Special Relativity. It was just a postulate that matter waves would also satisfy that equation.  
Hope it helps. Sorry for making it too long.                
