Home > Backend Development > C++ > How to Perform Case-Sensitive Comparisons with LINQ to Entities?

How to Perform Case-Sensitive Comparisons with LINQ to Entities?

Mary-Kate Olsen
Release: 2025-01-21 17:56:10
Original
749 people have browsed it

How to Perform Case-Sensitive Comparisons with LINQ to Entities?

Detailed explanation of case sensitivity comparison in LINQ to Entities

The following LINQ to Entities query:

<code class="language-c#">Thingies.First(t => t.Name == "ThingamaBob");</code>
Copy after login

Because LINQ to Entities converts lambda expressions into SQL statements, no case-sensitive comparisons are performed. The SQL_Latin1_General_CP1_CI_AS collation used by SQL Server by default is not case-sensitive.

Server-side solution

To enable case-sensitive comparisons, use the following SQL command to change the collation of the Name column in the Thingies table to COLLATE Latin1_General_CS_AS:

<code class="language-sql">ALTER TABLE Thingies ALTER COLUMN Name VARCHAR(25) COLLATE Latin1_General_CS_AS</code>
Copy after login

Client solution

Alternatively, you can use LINQ to Objects to perform a case-sensitive comparison, but this is less efficient:

<code class="language-c#">Thingies.Where(t => t.Name == "ThingamaBob")
        .AsEnumerable()
        .First(t => t.Name == "ThingamaBob");</code>
Copy after login

The above is the detailed content of How to Perform Case-Sensitive Comparisons with LINQ to Entities?. 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