title: EF can you make a Mutli-column Index using shadow properties?
body: <p>I'm trying to create a multi-column unique index using a shadow property. I know I can solve this problem with just adding a property, but I would like to see if this is possible in a way to keep my model clean.</p>
  
  <p>To create a multi-column index you have the following option in Fluent API:</p>
  
  <pre><code>modelBuilder.Entity&lt;AlbumTrack&gt;().HasIndex(t =&gt; new { t.TrackNumber, t.AlbumId).IsUnique();
  </code></pre>
  
  <p>But I don't want to clutter my model with an extra <code>AlbumId</code> property and thus would like to use a shadow property, for a single column this works as followed:</p>
  
  <pre><code>modelBuilder.Entity&lt;AlbumTrack&gt;().HasIndex(t =&gt; EF.Property&lt;int&gt;(t,"AlbumId")).IsUnique();
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>modelBuilder.Entity&lt;AlbumTrack&gt;()
      .HasIndex(t =&gt; new { t.TrackNumber, EF.Property&lt;int&gt;(t,"AlbumId")})
      .IsUnique();
  </code></pre>
  
  <p>However my IDE throws the following error:</p>
  
  <blockquote>
    <p>Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.</p>
  </blockquote>
  
  <p>Anybody has an idea how to do this with using a shadow properties or is this just not possible?</p>
  
  <p><em>edit: various grammar arrors.</em></p>