title: LINQ to Entities does not recognize the method ... get_Item(Int32)
body: <p>(Please read before marking as duplicate as my particular scenario is unique)</p>
  
  <p>I have the following code: </p>
  
  <pre><code>        // Get each treasure hunt
          var treasureHunts = dbContext.TreasureHunts.Where(i =&gt; i.UserName == User.Identity.Name).ToList();
  
          // Populate each treasure hunt with the list of leaderboard entries
          for (int i = 0; i &lt;= treasureHunts.Count; i++)
          {
              treasureHunts[i].Leaderboard = dbContext.Leaderboard.Where(
                  leaderboard =&gt; leaderboard.TreasureHuntId == treasureHunts[i].TreasureHuntId).ToList();
          }
  </code></pre>
  
  <p>On running the program, I get the following error from the second database query (dbContext.Leaderboard.Where...): </p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method
    'QrCodeTreasureHunter.Models.TreasureHuntDetails get_Item(Int32)'
    method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>In the first query, I'm getting each of the treasure hunts associated with a particular user. </p>
  
  <p>In the second part, I'm attempting to iterate through each of the treasure hunts, and populate the treasure hunt's Leaderboard List property with the associated leaderboard entries from my Leaderboard table. </p>
  
  <p>From what I understand from reading around is that this query isn't possible in its current form with Entity Framework. </p>
  
  <p>What workarounds or solutions would you be able to recommend to solve this problem? The ideal solution would involve no changes to the data models. </p>
  
  <p>If it's relevant, here is the TreasureHunt model: </p>
  
  <pre><code>    public class TreasureHuntDetails
  {
      public TreasureHuntDetails()
      {
          Clues = new List&lt;Clue&gt;();
          Leaderboard = new List&lt;Leaderboard&gt;();
  
          var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
          var dcs = new DataContractSerializer(typeof (TreasureHuntDetails), null, int.MaxValue,
                                               false, true, null);
          xml.SetSerializer&lt;TreasureHuntDetails&gt;(dcs);
      }
  
      [Key]
      public int TreasureHuntId { get; set; }
      [Required]
      public virtual string UserName { get; set; }
      [Required]
      public String Name { get; set; }
      public String Description { get; set; }
      [Required]
      public String Password { get; set; }
      public String CompletionMessage { get; set; }
      public String State { get; set; }
      public List&lt;Clue&gt; Clues { get; set; }
      public List&lt;Leaderboard&gt; Leaderboard { get; set; } 
  }
  </code></pre>
  
  <p>And here is the Leaderboard model: </p>
  
  <pre><code>    public class Leaderboard
  {
      [Key]
      public int Id { get; set; }
      public int TreasureHuntId { get; set; }
      public string Name { get; set; }
      public string Email { get; set; }
      public int Completion { get; set; }
  
      public DateTime? StartTime { get; set; }
      public DateTime? EndTime { get; set; }
      public Int64 TimeTaken { get; set; }
  
      public TreasureHuntDetails TreasureHuntDetails { get; set; }
  }
  </code></pre>
  
  <p>Good luck! </p>