Answer
$$y = \frac{1}{2}x - \frac{1}{4} + C{e^{ - 2x}}$$
Work Step by Step
$$\eqalign{
& x\frac{{dy}}{{dx}} + 2xy - {x^2} = 0 \cr
& {\text{this equation is not written in the form }}\frac{{dy}}{{dx}} + P\left( x \right)y = Q\left( x \right) \cr
& {\text{adding }}{x^2}{\text{ to both sides we obtain}} \cr
& x\frac{{dy}}{{dx}} + 2xy = {x^2} \cr
& {\text{now}}{\text{, divide both sides of the equation by }}x \cr
& \frac{{dy}}{{dx}} + 2y = x \cr
& {\text{the equation is already written in the form }}\frac{{dy}}{{dx}} + P\left( x \right)y = Q\left( x \right) \cr
& {\text{ we can note that }}P\left( x \right){\text{ is }}2 \cr
& {\text{The integrating factor is }}I\left( x \right) = {e^{\int {P\left( x \right)} dx}} \cr
& I\left( x \right) = {e^{\int 2 dx}} = {e^{2x}} \cr
& {\text{multiplying both sides of the differential equation }}\frac{{dy}}{{dx}} + 2y = x{\text{ by }}{e^{2x}} \cr
& {e^{2x}}\frac{{dy}}{{dx}} + 2{e^{2x}}y = x{e^{2x}} \cr
& {\text{Write the terms on the left in the form }}{D_x}\left[ {I\left( x \right)y} \right] \cr
& {D_x}\left[ {{e^{2x}}y} \right] = x{e^{2x}} \cr
& {\text{solve for }}y{\text{ integrating both sides}} \cr
& {e^{2x}}y = \int {x{e^{2x}}} dx\,\,\,\,\,\left( {\bf{1}} \right) \cr
& \cr
& {\text{integrating }}\int {x{e^x}} dx{\text{ by parts}}{\text{.}}\,\,\,{\text{set }}u = x,\,\,\,\,du = dx,\,\,\,\,\,\,\,dv = {e^{2x}},\,\,\,\,\,\,\,v = \frac{1}{2}{e^{2x}}{\text{. then}} \cr
& \,\,\,\,\,\,\,\int {x{e^{2x}}} dx = \frac{1}{2}x{e^{2x}} - \frac{1}{2}\int {{e^{2x}}dx} \cr
& \,\,\,\,\,\,\,\int {x{e^{2x}}} dx = \frac{1}{2}x{e^{2x}} - \frac{1}{4}{e^{2x}} + C \cr
& {\text{substituting the result of }}\int {x{e^{2x}}} dx{\text{ in }}\left( {\bf{1}} \right) \cr
& {e^{2x}}y = \frac{1}{2}x{e^{2x}} - \frac{1}{4}{e^{2x}} + C \cr
& y = \frac{1}{2}x - \frac{1}{4} + \frac{C}{{{e^{2x}}}} \cr
& {\text{or}} \cr
& y = \frac{1}{2}x - \frac{1}{4} + C{e^{ - 2x}} \cr} $$