Error: Could not process type 'xxx []' because it does not have any known mappings at the value layer

0

In the controller I have my session built.

public const string ListaPermissao_SessionName = "ListaPermissao";

private List<ListaPermissao> ListaPermissaoEnvio
{
    get
    {
        if (Session[ListaPermissao_SessionName] == null)
            Session[ListaPermissao_SessionName] = new List<ListaPermissao>();
        return (List<ListaPermissao>)Session[ListaPermissao_SessionName];
    }
    set
    {
        Session[ListaPermissao_SessionName] = (List<ListaPermissao>)value;
    }
}

Class ListPermission:

public class ListaPermissao
{
    public ListaPermissao()
    {
        this.editado = false;
    }
    public int id { get; set; }
    public bool value { get; set; }
    public bool editado { get; set; }
}

At some point I need to retrieve a list of other objects, however to validate the @checked attribute I need to check this list / session.

var employees = from e in this.context.PermissaoGrupo.Where(x => x.IdGrupo == idGrupo && x.Ativo)
                where (id.HasValue ? e.Permissao.IdPermissaoPai == id : e.Permissao.IdPermissaoPai == null)
                        select new
                        {
                            id = e.IdPermissao,
                            text = e.Permissao.Descricao,
                            hasChildren = e.Permissao.Permissao1.Any(),
                            expanded = e.Permissao.Permissao1.Any(),
                            ord = e.Permissao.Ordem,
                            @checked = (idUsuario != 0 ? ListaPermissaoEnvio.Any(x => x.id == e.IdPermissaoGrupo && x.value) : false),
                            idPermissaoGrupo = e.IdPermissaoGrupo
                        };

The following error is returned:

  

Could not process type 'Permission List []' because it does not have any known mapping to the value layer.

Thank you in advance.

    
asked by anonymous 06.07.2017 / 16:34

1 answer

0

After a few attempts I was able to solve it by just putting .AsEnumerable () before the query, I just found it strange that in the way I normally use the queries, it did not work ...

Usually I would use:

context.PermissaoGrupo.Include(x => x.Permissao).AsEnumerable()
.Where(x => x.IdGrupo == idGrupo && x.Ativo && (id.HasValue ? x.Permissao.IdPermissaoPai == id : x.Permissao.IdPermissaoPai == null))
.Select(x => new
{
    id = x.IdPermissao,
    text = x.Permissao.Descricao,
    hasChildren = x.Permissao.Permissao1.Any(),
    expanded = x.Permissao.Permissao1.Any(),
    ord = x.Permissao.Ordem,
    @checked = (idUsuario != 0 ? ListaPermissaoEnvio.Any(z => z.id == x.IdPermissaoGrupo && z.value) : false),
    idPermissaoGrupo = x.IdPermissaoGrupo
});

It worked like this:

from x in this.context.PermissaoGrupo.Include(x => x.Permissao).AsEnumerable()
where (x.IdGrupo == idGrupo && x.Ativo && (id.HasValue ? x.Permissao.IdPermissaoPai == id : x.Permissao.IdPermissaoPai == null))
select new
{
    id = x.IdPermissao,
    text = x.Permissao.Descricao,
    hasChildren = x.Permissao.Permissao1.Any(),
    expanded = x.Permissao.Permissao1.Any(),
    ord = x.Permissao.Ordem,
    @checked = (idUsuario != 0 ? ListaPermissaoEnvio.Any(z => z.id == x.IdPermissaoGrupo && z.value) : false),
    idPermissaoGrupo = x.IdPermissaoGrupo
};

If anyone knows why and share with us ....

    
06.07.2017 / 19:43