Home >Backend Development >C++ >How Can I Perform a Case-Insensitive Contains Operation with LINQ?
Case-Insensitive LINQ Contains Operation
In this code snippet, the Contains method in the Where clause is case-sensitive, meaning it will not return results if the specified string description differs in capital and lowercase letters from the values in the DESCRIPTION column. To make the comparison case-insensitive, we can modify the following code:
public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description) { return this.ObjectContext.FACILITY_ITEM.Where(fi => fi.DESCRIPTION.ToLower().Contains(description.ToLower())); }
By calling ToLower() on both the column value and the input string, we convert them to lowercase before performing the comparison. This ensures that the operation is case-insensitive and will return results regardless of the case of the input string.
The above is the detailed content of How Can I Perform a Case-Insensitive Contains Operation with LINQ?. For more information, please follow other related articles on the PHP Chinese website!