How to convince Linq in Sql to generate Sql to compare strings with larger or smaller?

Say I have an MS-SQL 2005 table named "People" with the following lines:

|FirstName|LastName|
|JD       |Conley  |
|Joe      |Schmo   |
|Mary     |Jane    |

I want to execute an SQL statement, for example:

select * from People where FirstName > 'JD'

The problem I am facing is that I cannot think of a way to get LINQ to SQL to generate this SQL statement. Obviously, I cannot use the ">" and "<" operators on strings in C #.

+3
source share
1 answer

You want String.CompareTohere

var query = from p in db.People
            where p.FirstName.CompareTo("JD") > 0
            select p;
+3
source

Source: https://habr.com/ru/post/1711006/


All Articles