So one solution is to accept that sex can be just that: just sex. It can be something that you and a friend do, maybe regularly, maybe only once in a while. Like playing Tennis. You may be happy that you have a friend who you can play Tennis with. But you don't have to fall in love with your Tennis partner and share every other part of your life with them. This solution you can call "Compartmentalizing".
The thing is, even if you had a Tennis partner who said "I don't want to play Tennis with you any more", you'd probably still feel hurt. Having emotional bonds is not limited to just sexual partners, but to anyone that you spend time with. That level of hurt is probably proportional to how often you played Tennis together, and your expectations on how long you expected that relationship to last.
The other method is to not separate emotions from sex, but to just get better at accepting loss and death of relationships as a natural course of life that must be reckoned with. This solution you can call "Acceptance of Grief".