BETWEEN AN EQUIVALENT in LINQ

I am looking for the 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?

+2
source share
5 answers

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; 
+7
source

Just use regular comparison operators

 var result = ct_rates .Where(x => x.start_date <= myDate && x => x.endDate >= myDate); 
+3
source

something like that?

 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") 
0
source

In our case, Robert's answer was close to what I was looking for. In our data model, our "end" or "through" date columns are NULL.

The following was necessary:

 Category.Where( w => w.ValidFrom <= now && (w.ValidThru == null ? DateTime.MaxValue : w.ValidThru) >= now).Select(s => s).Dump(); 
0
source

I found this to work when you want to compare only part of the data.

 var results = from rate in ct_rates where rate.StartDate.Date <= date && rate.EndDate.Date >= date select rate; 
0
source

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


All Articles