10

如何在实体框架中使用 BETWEEN 关键字?

这是我的 SQL 查询

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

这是我的实体框架代码。

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

值 12.59 可以是变量

4

1 回答 1

17

您可以使用>=and <=withDateTime来获取范围。

HRMEntities HRM = new HRMEntities();
meal ml = HRM.meals.SingleOrDefault(p => p.SHIFTCODE == "Normal" 
                                    && p.StartTime <= yourTime 
                                    && (p.StartTime + duration) >= yourtime);
于 2012-08-27T10:26:29.177 回答