In EF Code First, the common reason you should model a foreign key relationship is because you can navigate between entities. Consider a simple Country and City script with impatient downloads defined for the following LINQ statement:
var someQuery = db.Countries .Include(co => co.City) .Where(co => co.Name == "Japan") .Select(...);
This will result in a query along the lines of:
SELECT * FROM Country co INNER JOIN City ci ON ci.CountryId = co.ID WHERE co.Name = 'Japan';
Without the foreign key index in City.CountryId SQL, you will need to scan the city table to filter the cities for the country during JOIN.
TL DR
Pointers to foreign keys are recommended , even if you do not filter directly by foreign key, you will still need it in Joins. The exceptions to this seem to be very far-fetched:
If the selectivity of the foreign key is very low, i.e. in the above scenario, if 50% of ALL cities in the country table were in Japan, then the Index would not be useful.
If you donโt navigate relationships at all.
Another optimization consideration is whether to use the foreign key in the Clustered Index child table (i.e., a cluster of cities by country). This is often useful in parent-child relationships: child tables, where the usual place is to get all the child rows for the parent at the same time.
source share