tags:

views:

43

answers:

3

Hi:

I am looking LINQ equivalent for the following query

Select * from ct_rate
WHERE
'2010-10-01 00:00:00'
BETWEEN start_date and end_date;

ANY IDEA?

Thanks in Advance

+4  A: 

You need to use two comparison operations:

DateTime date = new DateTime(2010, 10, 1);

var results = from rate in ct_rates
              where rate.StartDate <= date && rate.EndDate >= date
              select rate;
Reed Copsey
Felan
@Robert: Heh, great - really tired today :S Should stop answering questions, I suppose.
Reed Copsey
A: 

something like this?

var result = from context.ct_rate.Where(d => d.start_date >= "2010-10-01 00:00:00" && d.end_date <= "2010-10-01 00:00:00")
castis
Most likely this will not work, as it'll do a string comparison...
Reed Copsey
He never said the dates were stored as date objects
castis
(That's why I said most likely - but string comparisons with dates are typically not what people want or expect)
Reed Copsey
+1  A: 

Just use ordinary comparison operators

var result = ct_rate
    .Where(x => x.start_date <= myDate && x => x.endDate >= myDate);
Robert Harvey