title: How to force RIA Services to include a sub-entity in one Query method but not another
body: <p>Here's the scenario: </p>
  
  <p>I've got an association between "Groups" and "Users, represented by a "UserGroupAssignment" object.</p>
  
  <pre><code>public class UserGroupAssignment
  {
    [Key]
    public virtual long Id { get; set; }
  
    [Association("UserAssignmentToUser", "UserId", "Id", IsForeignKey = true)]
    public virtual User { get; set; }  
  
    [Association("UserAssignmentToGroup", "GroupId", "Id", IsForeignKey = true)]
    public virtual Group { get; set; }    
  
    public virtual bool IsPrimary { get; set; }    
  
    public virtual DateTime? ValidFrom { get; set; }    
  
    public virtual DateTime? ValidTo { get; set; }    
  }
  </code></pre>
  
  <p>I have two business logic methods, GetUserAssignmentsForGroups and GetGroupAssignmentsForUsers that I return the assignments with the User and Group properties populated respectively. i.e. GetUserAssignmentsForGroup takes a GroupId and returns the assignments for that Group with the User property populated.</p>
  
  <p>What I want is to expose those two methods as domain query methods like so:</p>
  
  <pre><code>[Query]
  public IQueryable&lt;UserGroupAssignment&gt; GetAssignmentsForGroupWithUsers(long groupId)
  {
    return this.businessLogic.GetUserAssignmentsForGroups(groupId);
  }
  
  [Query]
  public IQueryable&lt;UserGroupAssignment&gt; GetAssignmentsForUserWithGroups(long userId)
  {
    return this.businessLogic.GetGroupAssignmentsForUsers(userId)
  }
  </code></pre>
  
  <p>My problem is that whilst the business logic methods return the correctly populated Assignments via NHibernate, RIA Services is NOT passing the sub-entities (User or Group) across the wire.</p>
  
  <p>I don't want to use [Include] attributes on the User or Group properties of the UserAssignment class, as I want to minimise the payload over the wire - I don't want to send the group over when I'm only interested in the User of each UserAssignment, for example.</p>
  
  <p>So my question is this:</p>
  
  <blockquote>
    <p><strong>How do I tell RIA services to
    explicitly include User sub-entities
    in one domain query method and Group
    sub-entities in the other?</strong></p>
  </blockquote>
  
  <p>Remember, I'm using NHibernate at the back end and custom query methods in the RIA Services, so can't use the EF-style include in the client query.</p>
  
  <p>Thanks</p>
  
  <p>Joel</p>