title: Fluent API - one to many
body: <p>I cannot seem to find a one-to-many relationship syntax in the fluent API.</p>
  
  <p>As an example I have two tables as below</p>
  
  <p><strong>User</strong></p>
  
  <pre><code>Id
  Name
  </code></pre>
  
  <p><strong>UserHistory</strong></p>
  
  <pre><code>Id
  UserId
  Date
  </code></pre>
  
  <p>In the classes I have the following</p>
  
  <pre><code>public class User 
  {
       public int Id { get; set; }
       public virtual ICollection&lt;UserHistory&gt; Histories { get; set; }
  }
  
  public class UserHistory
  {
       public int Id { get; set; }
       public int UserId { get; set; }
       public DateTime Date { get; set; }
  }
  </code></pre>
  
  <p>I have tried the following but I am not sure if its actually correct.</p>
  
  <pre><code>modelBuilder.Entity&lt;User&gt;()
         .HasRequired(w =&gt; w.Histories)
         .WithMany();
  
  modelBuilder.Entity&lt;User&gt;()
         .HasMany(f =&gt; f.Histories)
         .WithOptional()
         .HasForeignKey(f =&gt; f.UserId);
  </code></pre>
  
  <p>What is the correct syntax for one-to-many relationship? </p>
  
  <p>Technically I could break it down to a many-to-many by adding a new table but I didn't want to introduce another table.</p>