If you introduce the chemical activity $a$ in thermodynamics you can write the general equation.
$$ \frac{a_C a_D}{ a_A a_B} = K$$
which is correct for any case. Under ideal assumptions we have a linear relationship between the activity and concentration in solution.
So with an arbitrary normalizing reference concentration $c_0$ (e.g. 1 mol/l) the equation becomes roughly:
$$ \frac{c_C / c_0 c_D / c_0}{ c_A / c_0 c_B / c_0} = K$$
As you see the $c_0$ cancel each other out and you end up with the textbook equation that consists only of concentrations.
So the equation applies if you can scale your activities linearly with concentrations. This is usually possible for homogeneous reactions and sometimes possible for heterogenous reactions (As can be seen from the other answer).
PS: Activities hence equilibrium constants are dimensionless. You always have a factor 1 (mol/l)$^n$ to cancel out the units of the concentrations, if you derive it correctly.