I am using C # .net
I have two text fields that if! empty should be part of the WHERE clause in the LINQ query.
Here is my code
var result = from a in xxxx select a; if(!string.IsNullOrEmpty(personName)) { return result.Where(a >= a.forename.Contains(personName) || a.surname.Contains(personName) } else if(!string.IsNullOrEmpty(dateFrom)) { return result.Where(a >= a.appStartDateTime >= dateFrom.Date) } else if(!string.IsNullOrEmpty(personName) && !string.IsNullOrEmpty(dateFrom)) { return result.Where(a >= a.forename.Contains(personName) || a.surname.Contains(personName) && a.appStartDateTime >= dateFrom.Date); }
I thought it would work, but I don't like it. Where and I can not access "a", for example, a.forename (the name "a" does not exist in the current context)
How am I mistaken, or is it really cannot be done?
Thanks in advance for your help.
Clare
Clarebear
source share