title: Web Api for OData V4 doesn't Work With HasKey
body: <p>I'm using web api 2.2 for odata v4, and below is the models:</p>
  
  <pre><code>[Table("User")]
  public partial class User
  {
      public User()
      {
          UserRoles = new HashSet&lt;UserRole&gt;();
      }
  
      [StringLength(50)]
      public string Id { get; set; }
  
      [Required]
      [StringLength(50)]
      public string Name { get; set; }
  
      public virtual ICollection&lt;UserRole&gt; UserRoles { get; set; }
  }
  
  [Table("UserRole")]
  public partial class UserRole
  {
      [Key]
      [Column(Order = 0)]
      [StringLength(50)]
      public string UserId { get; set; }
  
      [Key]
      [Column(Order = 1)]
      [StringLength(50)]
      public string RoleName { get; set; }
  
      public virtual User User { get; set; }
  }
  </code></pre>
  
  <p>and below is the WebApiConfig.cs code:</p>
  
  <pre><code>        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
          builder.EntitySet&lt;User&gt;("Users");
          builder.EntitySet&lt;UserRole&gt;("UserRoles");            
          config.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
          config.AddODataQueryFilter();
  </code></pre>
  
  <p>Till now, every thing works well.
  But, if I remove the [Key] form the UserRole definition. and use the code :</p>
  
  <pre><code>builder.EntitySet&lt;UserRole&gt;("UserRoles").EntityType.HasKey(r =&gt; new { r.UserId, r.RoleName });
  </code></pre>
  
  <p>The when I query on User, I always get the error that tells UserRoles has no key definition.</p>
  
  <p>I have upload the source porject files @ <a href="https://cloud.seafile.com/f/bdff340ec3/" rel="nofollow">https://cloud.seafile.com/f/bdff340ec3/</a>
  Please check the webapiconfig.cs User.cs UserRole.cs and web.config (for database connection string).
  When you access /odata/Users?$expand=UserRoles you will get the error</p>