title: Linq to Entities error when comparing int? to a values
body: <p>I am trying to write a recursive function that will traverse a tree.  I have my entity 'Folder' with two properties of ParentFolderID and FolderID.  If the folder is at root level, then its ParentFolderID is null.  I created a recursive function that accepts a paramater ID and adds returns all the folder entities with the same ParentFolderID as ID, but I'm getting the error of 'Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.'.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>    private List&lt;Folder&gt; GetFolderChildren(int? folderId)
      {
          var childFolders = new List&lt;Folder&gt;();
  
          //  finalList is List&lt;&gt; that is actually returned
          var finalList = new List&lt;Folder&gt;();
  
          //  Your looking at the root level folder
          if (folderId == null)
          {
              childFolders = DocumentEntities.Folders.Where(x =&gt; x.ParentFolderID.Equals(folderId)).ToList();
          }
          else
          {
              childFolders = DocumentEntities.Folders.Where(x =&gt; x.ParentFolderID == folderId).ToList();
          }
  
          //  If there are no childFolders, then you've hit the bottom of this branch.  Return this folder.
          if (!childFolders.Any())
          {
              finalList.Add(DocumentEntities.Folders.SingleOrDefault(x =&gt; x.FolderID == folderId));
          }
          else
          {
              foreach (var childFolder in childFolders)
              {
                  finalList.AddRange(GetFolderChildren(childFolder.FolderID, pageName));
              }
  
              //  Now that you've gone through this folders children, add this folder
              finalList.Add(DocumentEntities.Folders.SingleOrDefault(x =&gt; x.FolderID == folderId));
          }
  
          return finalList;
      }
  </code></pre>
  
  <p>It never reaches the foreach when the folderID is null nor when its an int.  Any ideas?</p>