Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Equivalent for SQL BETWEEN

Is there a LINQ To SQL equivalent to the SQL between keyword?

Do I just need to And both comparisons?

SELECT first_name, last_name
  FROM people
 WHERE last_name between 'Smith' and 'Thompson'
like image 962
Steven Avatar asked Jun 16 '26 08:06

Steven


1 Answers

I assume you mean "in Linq to Sql". Linq by itself just passes the expression to the LinqProvider which translates it into something appropriate for the data store being queried.

That being said, I'm pretty sure that the MSSQL provider used by Linq to Sql will translate last_name >= "Smith" and last_name <= "Thomson" into a BETWEEN expression.

UPDATE: Empirical evidence (via LINQPad) shows that it does not translate to BETWEEN

like image 173
James Curran Avatar answered Jun 19 '26 19:06

James Curran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!