I am working on an ASP.NET MVC application that uses a repository template with LINQ to SQL as a data source. In my repository, I expose the following method:
public IEnumerable<T> Find(Expression<Func<T, bool>> where)
{
return _context.GetTable<T>().Where(where);
}
I can call it by saying:
repository<User>().Find(u => true);
But if I try to do (when the search is zero)
repository<User>().Find(u => !string.IsNullOrEmpty(search) ? u.UserName.Contains(search) : true);
I get an error message:
The value cannot be null. Parameter Name: Text
I thought the lambda expression would do the same thing since the search value is null, but this is clearly not the case.
How to fix this problem?
source
share