Linq to sql Linq2SQL在哪之间

Linq to sql Linq2SQL在哪之间,linq-to-sql,between,Linq To Sql,Between,在Linq到SQL的SQL中是否可以执行此操作 Select field from table where date between '2010-01-01' and '2010-01-31'; 我意识到我可以做到: where (monthBeginDate < a.StopDateActual && a.StopDateActual < monthEndDate) where(monthBeginDate

在Linq到SQL的SQL中是否可以执行此操作

Select field from table where date between '2010-01-01' and '2010-01-31';
我意识到我可以做到:

where (monthBeginDate < a.StopDateActual && a.StopDateActual < monthEndDate)
where(monthBeginDate

但我很好奇我是否能做到前者。我有一个坏习惯,就是在这样的陈述中把小于和大于的部分搞糟。

不,这就是方法。我相信C#没有中间运算符

你可以像我一样作弊并编写扩展方法:

public static bool BetweenDates (this DateTime checker, DateTime floor, DateTime ceiling)
{
    return (checker <= ceiling) && (checker >= floor);
}

您可以执行以下操作:

public bool Between(DateTime value, DateTime from, DateTime To) {
   return value > from && value < to;
}

where Between(a.StopDateActual, monthBeginDate, monthEndDate)
public bool-Between(DateTime值、DateTime-from、DateTime-To){
返回值>从&&value

但是,您应该注意,这适用于
IEnumerable
,而不适用于
IQueryable
,即在应用where之前,将从数据源提取结果。在大量数据的情况下,这可能是一个性能问题,因此,where clasue是您所能做到的最好的。。。只要小心>和<

杜普:那里的解决方案非常复杂。对不起,我不清楚这是同一个问题。对我来说,这是一个不同的问题。我觉得我的问题更直接。这似乎比我要求的更多。@masenkablast-是什么让解决方案变得复杂,也是什么让它更有效。使用表达式可以将其转换为SQL,而不必具体化查询,然后将谓词应用于结果。在这种情况下,我宁愿接受一次“性能冲击”(在编写代码时),而不是每次运行它。@tvanfosson每天都能学到一些东西不,它没有中间运算符。这没那么重要。我只是想我可能错过了什么。很高兴看到我没有。
public bool Between(DateTime value, DateTime from, DateTime To) {
   return value > from && value < to;
}

where Between(a.StopDateActual, monthBeginDate, monthEndDate)