I have a linq query that is passed into NHibernate which Linq2NHibernate will parse and return me populated entities.
string firstName = "Ryan";
Store store = _repository.Query<Store>().Where(x => x.Employees.Select(y => y.FirstName).Contains(firstName)).FirstOrDefault();
The troublesome part is x => x.Employees.Select(y => y.FirstName).Contains(firstName)
What this should be doing is selecting Stores that have Employees with the name Ryan.
I receive an error on the line above stating "Unhandled Expression Type: 1004"
It appears to me that it is a limitation of Linq2NHibernate and the .Select().Contains()
just can't be parsed.
Any ideas? Has anyone else every received this error? What can I do to fix it or work around it?
[EDIT]
Here is what I ended up using instead.
string firstName = "Ryan"
Store store = _repository.Query<Store>().Where(x => x.Employees.Any(y => y.FirstName == firstName)).FirstOrDefault();
The Linq query being x => x.Employees.Any(y => y.FirstName == firstName)