title: Problem with EF Code First foreign key inference
body: <p>I'm working with EF Code First for the first time, and I'm having trouble getting it to infer the relationships between my types.   Given these two types:</p>
  
  <pre><code>&lt;Table("grpGroupType")&gt;
  Public Class GroupType
    &lt;Key()&gt;
    Public Property GroupTypeID As Integer
  
    &lt;Required()&gt;
    Public Property IsActive As Boolean
  
    &lt;Required()&gt;
    &lt;MaxLength(100)&gt;
    Public Property Description As String
  
    Public Overridable Property GroupDefinitions() As ICollection(Of GroupDefinition)
  End Class
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;Table("grpGroupDefinition")&gt;
  Public Class GroupDefinition
    &lt;Key()&gt;
    Public Property GroupDefinitionID As Integer
  
    &lt;Required()&gt;
    Public Property GroupTypeID As Integer
  
    &lt;Required()&gt;
    Public Property IsActive As Boolean
  
    &lt;Required()&gt;
    Public Property ScopeValue As Integer?
  
    &lt;Required()&gt;
    &lt;MaxLength(100)&gt;
    Public Property Description As String
  
    Public Overridable Property GroupType As GroupType
  End Class
  </code></pre>
  
  <p>I can load and save data using the DbContext class, but when I try to access GroupType.GroupDefinitions or GroupDefinition.GroupType, they both return Nothing. My DbContext class is here:</p>
  
  <pre><code>Public Class PD
    Inherits DbContext
  
    Public Property GroupDefinitions As DbSet(Of GroupDefinition)
    Public Property GroupTypes As DbSet(Of GroupType)
  
    Protected Overrides Sub OnModelCreating(ByVal modelBuilder As     ModelConfiguration.ModelBuilder)
      modelBuilder.Entity(Of GroupDefinition)().HasKey(Function(b) b.GroupDefinitionID)
      modelBuilder.Entity(Of GroupType)().HasKey(Function(b) b.GroupTypeID)
    End Sub
  End Class
  </code></pre>
  
  <p>There doesn't seem to be much documentation on key inference, but I did find this <a href="http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx" rel="nofollow">blog post</a> and it appears that my classes follow the rules for automatic inference.</p>
  
  <p>Could anyone point me in the right direction?</p>