title: Entity Framework's DbModel: How to map a one to many relationship using a connection table?
body: <p>I'm trying to map via DbModel this relationship present on the database.</p>
  
  <pre><code>CREATE TABLE core.Institutes 
  (
      ID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
      Name NVARCHAR(128) NOT NULL,
      OldID INT NULL
  )
  GO
  
  CREATE TABLE core.InstitutePlaces
  (
      FKInstituteID INT NOT NULL PRIMARY KEY REFERENCES core.Institutes(ID),
      FKPlaceID INT NOT NULL REFERENCES core.Places(ID)
  )
  GO
  
  CREATE TABLE core.Places
  (
      ID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
      Name NVARCHAR(128) NOT NULL,
      FKParentID INT NULL REFERENCES core.Places(ID),
      OldID INT NULL
  )
  GO
  </code></pre>
  
  <p>on this model</p>
  
  <pre><code>public class Place
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int? ParentId { get; set; }
      public Place Parent { get; set; }
  }
  
  public class Institute
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public Place Place { get; set; }
  }
  </code></pre>
  
  <p>we're using something like this to do the mapping</p>
  
  <pre><code>modelBuilder.Entity&lt;Institutes.Institute&gt;().HasOptional(i =&gt; i.Place);
  </code></pre>
  
  <p>but it doesn't work :(</p>
  
  <p>This scenario is perfectly managed by the EDML file, so the problem is only about the mapping.</p>