How to derive the demand function of $U(x_1,x_2)=x_1-x_2$ I'm trying to find the uncompensated demand function. How would you do that, when I have the following utility function $u(x_1,x_2)=x_1-x_2$, and the budget constraint $p_1\cdot x_1+p_2\cdot x_2=p_1\cdot e_1+p_2\cdot e_2$. 

I've found the following.

$\max\ u(x_1,x_2)=x_1-x_2 \ s.t. \ p_1(x_1-e_1)+p_2(x_2-e_2)=0$

With use of substitutions I must maximize the following expression

$\max\ u(x_1,x_2)=x_1-\frac{p_1(e_1-x_1)+p_2e_2}{p_2}$

I find the f.o.c.

$\frac{\partial u}{\partial x_1}=1+\frac{p_1}{p_2}=0$
Some economics problems are deisgned to help us practice the basic tools (e.g., optimisation) of the trade. Others are designed to force us to think about the mechanics of a problem to help us understand the underlying economics better.

This problem falls into the latter category, so I recommend you give up on trying to usual calculus (which is premised on finding some sort of indifference curve tangent) and play around with the problem to figure out why this approach isn't working.



A consumer with $u=x_1-x_2$ is indifferent between the bundles $(4,3)$ and $(3,2)$. We can plot these and other indifference budles to draw an indifference curve:



Likewise, the consumer is indifferent between $(4,4)$ and $(5,5)$ and we can, in this fashion, get an indifference map:



From inspection of the utility function we know that the consumer is better off with more $x_1$ and less $x_2$, so utility increases in the direction indicated.

Now we can pick an endowment vector (e.g,. $(2,4)$) and a relative price (e.g. $-p_1/p_2=-1$) and plot the price line:



The consumer can trade from their endowment to any point along this line. By inspection, you should be able to figure out what the demand vector $\mathbf{x}=(x_1,x_2)$ will be. 



Addendum: once you figure out what is going on here, your condition $$\frac{\partial u}{\partial x_1}=1+p_1/p_2$$
should make a bit more sense to you.