I’m new to .NET. I’m trying to do something very simple.
I would like to perform a search on a Model in my controller and retrieve the first entity returned :
var cercueils = from y in db.Cercueils select y;
cercueils = cercueils.Where(z => z.Type.ToUpper().Contains(dr[13].ToUpper())
|| z.AncienType.ToUpper().Contains(dr[13].ToUpper()));
Cercueil cercueil = cercueils.First();
But this is not good, as it throws an error :
Le type de nœud « ArrayIndex » de l'expression LINQ n'est pas pris en charge dans LINQ to Entities.
(Google translate: “the node type of the LINQ expression arrayIndex n is not supported in LINQ to Entities”)
How can I achieve that ?
Thanks for your help.
I believe Linq doesn’t know how to execute ‘dr[13]’ in the context of deferred execution…
try the following:
Also, I usually recommend FirstOrDefault with a null check afterwards 🙂