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

How Can I Perform Case-Insensitive LINQ Contains Queries?

Linda Hamilton
Release: 2025-01-04 20:46:40
Original
1019 people have browsed it

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));
}
Copy after login

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())
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template