title: Entity Framework subquery
body: <p>Guys I am new to Entity Framework and I'm having a bt of a problem that I have been trying to solve for quite a while.  Basically I have 4 entities: users, groups, books and readingLists.  A user can join a group and a group contains books - defined by readingList.  I am trying to display a list of books for a specific group, the SQL looks like this:</p>
  
  <pre><code>SELECT * FROM Books b
  WHERE b.Id IN (
      SELECT BookID FROM ReadingList rl
          WHERE rl.GroupID = '3')
  </code></pre>
  
  <p>I determine the GroupID being searched by querying the current user from a UserRepository and currently the 'get books by group' method is looking like this:</p>
  
  <pre><code>// Get books by group
  public IQueryable&lt;Book&gt; GetGroupBooks(string username)
  {
      UserRepository userRepository = new UserRepository();
      int groupId = userRepository.GetUserGroupId(username);
  
      IQueryable&lt;Book&gt; q = from b in entities.Books 
                           where b.Id == 7 // temp - these values should be determined by 
                                           // rl in entites.ReadingList select rl.BookID where r.GroupID == groupID
                           select b;
  
      return q;
  }
  </code></pre>
  
  <p>Obviously this is a temporary measure and only returns one book, but I have included it for reference.  Any help or advice here would be much appreciated.</p>
  
  <p>Thanks</p>