Home >Backend Development >C++ >How Can I Perform Case-Insensitive LINQ Contains Queries?

How Can I Perform Case-Insensitive LINQ Contains Queries?

Linda Hamilton
Linda HamiltonOriginal
2025-01-04 20:46:401045browse

How Can I Perform Case-Insensitive LINQ Contains Queries?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn