IMO:
1) Elhanan was one of the Thirty Champions of David (whether in historical reality, or not, need not concern us);
2) Elhanan killed Goliath;
3) the killing of Goliath was ascribed to David by a later generation, because David was Elhanan's employer.
Another possibility: Elhanan was the personal name of the individual whose throne name is David.
Both possibilities may be correct; they are not incompatible.