Retrieving an object's ID
This will be shorter, it takes less selects, and may runs at SQL server side

return rep.FindWhere(i =&gt; i.ID == itemID)
          .SelectMany(i =&gt; i.Batch.Items)
          .Where(i =&gt; i.StatusID == (short) ItemStatus.Pending)
          .MaxBy(i =&gt; i.NumInBatch).ID;