How to use BETWEEN keyword in Entity Framework?

between c# entity-framework

Question

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

1
9
8/27/2012 10:24:41 AM

Accepted Answer

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);
13
8/27/2012 10:26:29 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow