I have some code that is working, but I don't know how. I'm asking this question in hopes that someone can explain how it is working, as any searching I do online gives me information that's not quite specific to what I'm seeing.
I have two entities.
EntityA, EntityB.
EntityA has this:
public partial class EntityA
{
...
public Guid EntityBGuid { get; set; }
public virtual EntityB EntityB { get; set; }
}
EntityB has this:
public partial class EntityB
{
...
public virtual ICollection<EntityA> EntityAs{ get; set; }
}
Nowhere in DatabaseEntities.cs > OnModelCreating() is a relationship defined for either entity.
Nowhere in either table in SQL is there a FK defined for the relationship.
So when I do something like this:
context.LettingProjects.Where(query).Select(s => s.Call).ToList(); //Crash.
But with a .Include, I get data:
context.LettingProjects.Include(i => i.Call).Where(query).Select(s => s.Call).ToList(); //Results.
My question is how does this even work? I don't know how EF handles this in the background, and it seems like a gotcha waiting to happen.