Performing Case-Insensitive LINQ Contains Queries
In certain scenarios, performing case-sensitive LINQ queries may not be suitable. To make a query case insensitive, the ToLower() method can be utilized on the desired string properties.
To illustrate, consider the following code:
public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description) { return this.ObjectContext.FACILITY_ITEM.Where(fi => fi.DESCRIPTION.Contains(description)); }
In this code, the Contains() method used in the WHERE clause performs a case-sensitive comparison. To make it case insensitive, the ToLower() method can be applied as follows:
fi => fi.DESCRIPTION.ToLower().Contains(description.ToLower())
The updated code now performs a case-insensitive comparison between the DESCRIPTION property of the entities in the FACILITY_ITEM table and the description parameter. This will ensure that the query returns results regardless of the casing of the input string.
The above is the detailed content of How Can I Perform Case-Insensitive LINQ Contains Queries?. For more information, please follow other related articles on the PHP Chinese website!