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!