I want to do a query in C# (EF Core and LINQ), where the query is structured like this:
SELECT someField
FROM SomeTable
WHERE someField >= 'A 100' AND someField <= 'A 150'
The SQL works just fine, but I cannot find a way to translate that into LINQ with EF Core.
The 2 strings should be string parameters for the query.
What I have tried so far:
- lambda-expression like
.Where(s => s.someField >= lowerBoundary)
. Problem: The compiler does not like that at all. - Use String.Compare like this
.Where(p => string.Compare(p.someField, searchCriteria.lowerBoundary) >= 0 && string.Compare(p.someField, searchCriteria.upperBoundary) <= 0);
** Update (edit): This DOES work**. For some reason it did not in my first try when it was mixed up with other parts of my more complex query.
I have used EF Core 3.1.1
Any ideas?