As I was investigating the difference between Include
and Join
I found that :
If the DB does not include a Foreign Keys -it has n
Suppose that in your class there is a [Required]
constraint on City or CityID. And suppose there are Person records without a (valid) City. The only way to satisfy the [Required]
is to perform an inner join.
But as long as the constraints in your Db and model match (ie CityID INT NOT NULL
) it wouldn't really matter what kind of Join is used. That should be the normal case.
And without the constraint you would of course expect a Left Join.
I know this is an old question, but if anyone else lands here using EF Code First as I am, my issue was in the fluent mappings:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Parent>()
.HasOptional(a => a.Child) /* LEFT OUTER JOIN */
.WithMany()
.HasForeignKey(a => a.ChildId);
}
is translated as a LEFT OUTER JOIN whereas
modelBuilder.Entity<Parent>()
.HasRequired(a => a.Child) /* INNER JOIN */
.WithMany()
.HasForeignKey(a => a.ChildId);
is translated as an INNER JOIN.