MVC EF first result query is replaced by second result if second result got the same record
<p>I used Entity Framework 5.
I had a table hotel which had a collection of roomTypes.</p>

<p>When I wanted to find which hotel had the following roomTypes by looped the function for each roomType and merged the result. The first result was replaced by the second result if it contained the same record.</p>

<pre><code>Model
public class Hotel {
  public int id { get; set; }
  public string hotelName { get; set; }

  [ForeignKey("HotelId")]
  public ICollection&lt;RoomType&gt; RoomTypes { get; set; }
}

public class RoomType {
  public int id { get; set; }
  public string name { get; set; }
  public int hotelId { get; set; }
}

Caller    
public JsonResult GetHotelByRoomTypes(string[] roomTypeNames) {
  List&lt;List&lt;Hotel&gt;&gt; hotels = new List&lt;List&lt;Hotel&gt;&gt;();
  foreach (string roomTypeName in roomTypeNames) {
    List&lt;Hotel&gt; partialHotel = hotelRepo.GetHotelsFromRoomType(roomTypeName);
    hotels.Add(partialHotel);
  }
  return Json(hotels);
} 

HotelRepo
public List&lt;Hotel&gt; GetHotelsFromRoomType(string roomType) {
  List&lt;RoomType&gt; roomTypes = db.RoomTypes.Where(r =&gt; r.name.Equals(roomType)).ToList();
  copy hotelId from roomTypes into int[] hotelIds
  List&lt;Hotel&gt; hotels = db.Hotels.Where(h =&gt; hotelIds.Contains(h.id)).ToList();
  return hotels 
}
</code></pre>

<p>My problem was if I sent 2 roomTypes ["deluxe", "suite"]. Then I got a List of <strong>HotelA</strong> and <strong>HotelB</strong> as a <strong>first result</strong>. Both of them contained a collection of roomType of "deluxe". After that, I put these 2 hotels into the List>. </p>

<p>Then the <strong>second result</strong> returned <strong>HotelA</strong> and <strong>HotelC</strong> which HotelA contained the collection of roomType "suite". </p>

<p>When this happended, HotelA of the first result would be the same as HotelA of the second result which held only "suite" in the roomTypes collection and "deluxe" in hotelA was missing.</p>

<p>Do you have any suggestions?</p>