Why does the following exception occur when using Split
within a Select
in a IQueryable
?
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
I've been able to solve the problem using ToList
and doing Select
with Split
on it, but I'd like to understand what the problem is.
So exception occurs:
var retorno = entities.tabela.Where(x => x.coluna1 == null)
.Select(x => new { Campo1 = x.coluna1, Campo2 = x.coluna2 });
retorno = retorno.Select(x => new { x.Campo1, Campo2 = x.Campo2.Split(' ')[0] });
How it works:
var retorno = entities.tabela.Where(x => x.coluna1 == null)
.Select(x => new { Campo1 = x.coluna1, Campo2 = x.coluna2 }).ToList();
retorno = retorno.Select(x => new { x.Campo1, Campo2 = x.Campo2.Split(' ')[0] }).ToList();