Could not create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context

5

I'm trying to make a query in LINQ, and are returning the following error message:

  

A constant value of type 'System.Object' could not be created. Only primitive types or enumeration types are supported in this context

A structure is recursive, so one structure can be the daughter of another.

When I get the idPai , I want it to bring only the children of that structure, and when I pass id , I want that specific structure, that idPai .

Action would look like this:

Estrutura/{idPai}/{id}

The query is as follows:

var list = (from e in ent.Estrutura
join t in ent.TipoEstrutura on e.idTipoEstrutura equals t.id

join ee in ent.Estrutura on e.idEstrutura equals ee.id into eleft
from ePai in eleft.DefaultIfEmpty()


where ((idPai.HasValue ? e.idEstrutura.Equals(id) : e.idEstrutura.Equals(null))
        && (id.HasValue ? e.id.Equals(id) : e.id != null))

select new SigProcessos.Entity.ViewModel.Estrutura
{
    Id = e.id,
    IdEstrutura = e.idEstrutura,
    IdTipoEstrutura = t.id,
    DescricaoEstrutura = e.descricao,
    DescricaoEstruturaPai = (null != ePai ? ePai.descricao : default(string))
}).ToList();

return list;

Thanks for the help!

    
asked by anonymous 02.03.2016 / 15:25

1 answer

0

Try changing your% of% to "==".

Since you have variables that are probably of type .Equals() , you may be experiencing a problem because the program may be trying to int? with incorrect types (example: .Equals() ).

    
02.03.2016 / 18:33