Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use BETWEEN keyword in Entity Framework?

How do i use BETWEEN key word in Entity Framework?

This is my SQL query

    SELECT *
  FROM [HRM].[dbo].[meals]
  WHERE SHIFTCODE = 'Normal'
  AND 12.59 BETWEEN [STAR TIME] AND [STAR TIME]+DURATION/10;

This is my Entity Framework Code.

HRMEntities HRM = new HRMEntities();
            meal ml = HRM.meals.SingleOrDefault(p => p.SHIFTCODE == "Normal");

value 12.59 can be a variable

like image 787
Tharik Kanaka Avatar asked Aug 27 '12 10:08

Tharik Kanaka


1 Answers

You can use >= and <= with DateTime to get a range.

HRMEntities HRM = new HRMEntities();
meal ml = HRM.meals.SingleOrDefault(p => p.SHIFTCODE == "Normal" 
                                    && p.StartTime <= yourTime 
                                    && (p.StartTime + duration) >= yourtime);
like image 162
Habib Avatar answered Oct 18 '22 03:10

Habib