views:

49

answers:

2

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'
+3  A: 

I'm pretty sure that there is no way to do a "BETWEEN" via LINQ. You have to do it just like you said, by ANDing your upper and lower bounds.

Charles Boyung
+2  A: 

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

James Curran