title: Creating a unique index between two navigation properties using Entity Framework Code-First v6.0
body: <p>I'm working on an Entity Framework 6 Code First project and I need to create a <em>Unique Index</em> that include two navigation properties.</p>
  
  <p>For some unknown reason when I do the migration <em>add-migration Foo</em> the generated code create two separated indexes (one for each property).</p>
  
  <p>Here's the code snippet of the generated code</p>
  
  <pre><code>.Index(t =&gt; t.a)
  .Index(t =&gt; t.b)
  </code></pre>
  
  <p>Now if I do the same with two non-navigation properties the generated code is the expected</p>
  
  <p>Here's the code snippet with the properties and the data annotations</p>
  
  <pre><code>[Index("IX_1", 1, IsUnique = true)]
  public int a { get; set; }
  
  [Index("IX_1", 2, IsUnique = true)]
  public int b { get; set; }
  </code></pre>
  
  <p>and here's the code snippet of the generated code (the expected one)</p>
  
  <pre><code>.Index(t =&gt; new { t.a, t.b }, unique: true, name: "IX_1")
  </code></pre>
  
  <p>I'm applying the same annotations with the non-navigation properties and the navigation properties.</p>
  
  <p>Why it doesn't generate the correct code with navigation properties?</p>
  
  <p>Can somebody tell me if there's a way to make it works with the navigation properties?</p>