c# - Linq to Entities error when comparing int? to a values -


i trying write recursive function traverse tree. have entity 'folder' 2 properties of parentfolderid , folderid. if folder @ root level, parentfolderid null. created recursive function accepts paramater id , adds returns folder entities same parentfolderid id, i'm getting error of 'unable create constant value of type 'system.object'. primitive types or enumeration types supported in context.'.

here function:

    private list<folder> getfolderchildren(int? folderid)     {         var childfolders = new list<folder>();          //  finallist list<> returned         var finallist = new list<folder>();          //  looking @ root level folder         if (folderid == null)         {             childfolders = documententities.folders.where(x => x.parentfolderid.equals(folderid)).tolist();         }         else         {             childfolders = documententities.folders.where(x => x.parentfolderid == folderid).tolist();         }          //  if there no childfolders, you've hit bottom of branch.  return folder.         if (!childfolders.any())         {             finallist.add(documententities.folders.singleordefault(x => x.folderid == folderid));         }         else         {             foreach (var childfolder in childfolders)             {                 finallist.addrange(getfolderchildren(childfolder.folderid, pagename));             }              //  you've gone through folders children, add folder             finallist.add(documententities.folders.singleordefault(x => x.folderid == folderid));         }          return finallist;     } 

it never reaches foreach when folderid null nor when int. ideas?

if x.parentfolderid null, not access in equals method because null. try compare entire value argument since has same type, sample

childfolders = entities.folders.where(x => x.parentfolderid == folderid).tolist(); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -