Simple question but cant seem to find the answer I am looking for.
I am getting an error on the checking of two bools in a where clause in an EF query.
I have this:
filteredClients.Where(c => c.Company == Convert.ToBoolean(keyValuePair.Value));
clientFilters.Company is a nullable bool where as the Entity in the DB, "Company" is a bool.
However, Checking the results this is not being processed properly.
I've set the KeyValuePair.Value which is a string "True" and then converted it to a bool.
This is whats in the table:
and after the query has been executed I still get all my records not just 4.
How do I write this where clause so that I get the selection of only records that have "true" set for the column "Company"?
From what I can read, you don't appear to be setting the filteredClients reference as a result of the Where operation:
It should look more like:
filteredClients = filteredClients.Where(c => c.Company == Convert.ToBooolean(keValuePair.Value));
If you get a casting error about IQueryable not matching IEnumerable or the like, make sure your initial/earlier setting of filteredClients is not prematurely executing with a .ToList()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.