Error: Could not parse type 'xxx[]' because it does not have any known mapping to the value layer

Asked

Viewed 97 times

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 recover a list of other objects, but 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 parse type 'Listpermission[]' because it does not have any known mapping to the value layer.

Thanks in advance.

1 answer

0

After a few attempts I managed to solve just by putting . Asenumerable() before the consultation, I just found it strange that in the form I normally use the consultations did not work...

Would normally 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 that way:

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 the reason and shares with us....

Browser other questions tagged

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