I tried to split a string in a linq query. I got an error says “Unrecognized expression node: ArrayIndex”. Does anyone know how to achive this? My code sample is:
List<Task> Result= (from t in TaskDB.Tasks
select new Task
{
Description = t.Description.Split('-')[0].ToString(),
Id = ts.id,
}).ToList();
The problem is that the
selectpart of your query can’t be converted into SQL to be executed on the server (hence the “unrecognised expression node” error). Try something like this, which insures that the necessary code is executed on the client side:The trick here is simply to call the
AsEnumerableextension method before selecting the items.