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

Asked

Viewed 687 times

5

I am trying to make a query in LINQ, and is returning the following error message:

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

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

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

Action would be like this:

Estrutura/{idPai}/{id}

The query is the following:

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;

I appreciate the help!

1 answer

0

Try changing your .Equals() for "==".

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.