Straight core electromagnet