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

How Can I Perform a Case-Insensitive Contains Operation with LINQ?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-04 15:37:391000browse

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!

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