Code without the disadvantage from the code of Pappenheimer see here:
Attach Entity