I’m making a function to search for members and I want to add a Where to my searchResults variable. However it might need to be an IQueryable before I could do so.
This is what I want to accomplish:
var searchResults = listMembers.DataSource = members.getAllMembers().OrderByDescending(x => x.createdDate).Select(x => new
{
x.ID,
x.memberNumber,
x.name,
x.email,
x.birthDate,
hasPayed = Helper.renderBoolImage(x.hasPayed, true),
isConfirmed = Helper.renderBoolImage(x.isConfirmed, true),
isExportedToExcel = Helper.renderBoolImage(x.isExportedToExcel, true)
});
if (!String.IsNullOrEmpty(search.name))
{
searchResults = searchResults.Where(x => x.name.ToLower().Equals(enc(search.name.ToLower())));
}
This line doesn’t compile though, since it cannot resolve the Where:
searchResults = searchResults.Where(x => x.name.ToLower().Equals(enc(search.name.ToLower())));
This is the problem:
You should use:
Currently the type of
searchResultsis the same as the type oflistMembers.DataSource, not the type ofmembers.getAllMembers...In general I’d advise against multiple assignments like your original code (
x = y = z) – it makes the code more confusing, as you’ve found…