Foreign keys can indeed speed up queries if they are trusted. If the engine knows that every value in ParentID
in the Child
table refers to a valid PK in Parents
then it won't even look at that table to check.
However, relational constraints are a good idea in general regardless. One philosophy behind constraints in the database is to use them as a last-resort stop for bad data. Foreign keys are a good example of this.
If you depend entirely on your ORM for relation management, what happens if you change to a different framework? You still need to keep your existing data. What happens if for some reason you need to make changes to your relational model in the ORM and orphaned child records get put in with no parent?
Short answer - yes, you should still use keys and constraints in the database.