Hi, I am working on an ASP.Net MVC application which uses the repository pattern with linq to sql as my 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 am able to call this by saying:
repository<User>.Find(u => true);
But if I try doing (when search is null):
repository<User>.Find(u => !string.IsNullOrEmpty(search) ? u.UserName.Contains(search) : true);
I get the error:
Value cannot be null. Parameter name: text
I thought the lambda expression would execute the same thing since the value of search is null but this is clearly not the case.
I'd appreciate it if someone could help. Thanks.