c# - Lambda expression weirdness in a LINQ to SQL 'where' condition -
I am working on an application that uses repository patterns with my data source. In my repository I expose the following method:
public IEnumerable & lt; T & gt; Find (convert & lt; Func & lt; T, bool & gt; & gt; ou)) Returns _ Convert GateTable & lt; T & gt; (). Where (where); }
I am able to call by saying:
repository & lt; Users & gt; (). Find (U => true);
But if I'm trying (when the search is zero)
the repository & lt; Users & gt; (). (U = & gt; String.EasanOrcti Search)? U.UserName.Contains (search): true);
I get an error:
The value can not be empty The parameter name: text
I thought That Lambda's expression will execute the same thing because the value of search is zero, but this is not clearly the case.
How do I fix this problem?
To add to other answers, if you is adhering to this ideal To do this, you can do so instead:
repository & lt; Users & gt; (U => String.EsanLolecti (search) || u.UserName.Contains (search));
Before applying it blindly with eyes, if you are to do so, then read Adam's answer to learn about the result.
Comments
Post a Comment