Linq2SQL 两者之间
是否可以在 Linq to SQL 中的 SQL 中执行此操作?
Select field from table where date between '2010-01-01' and '2010-01-31';
我意识到我可以做到:
where (monthBeginDate < a.StopDateActual && a.StopDateActual < monthEndDate)
但我很好奇我是否可以做到前者。我有一个坏习惯,就是在这样的陈述中搞砸小于和大于。
Is is possible to do this in SQL in Linq to SQL?
Select field from table where date between '2010-01-01' and '2010-01-31';
I realize I could do:
where (monthBeginDate < a.StopDateActual && a.StopDateActual < monthEndDate)
But I was curious if I could do the former. I have a bad habit of screwing up the less than and greater than on statements like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行以下操作:
但是,您应该注意,这适用于
IEnumerable
而不是IQueryable
,即结果将在应用 where 之前从数据源中提取。在大量数据的情况下,这可能是一个性能问题,因此,您的 where 子句是您能做的最好的...只需小心 >且< !!!You could do the following:
However, you should note that this works on
IEnumerable
and not onIQueryable
, i.e. the results will be pulled from the data source before the where is applied. This could be a performance issue in the case of a large ammount of data, therefore, your where clasue is the best you can do ... just be careful with the > and < !!!不,这就是这样做的方法。我相信 C# 没有 Between 运算符。
你总是可以像我一样作弊并编写一个扩展方法:
然后你可以这样做;-)
Nope, that's the way to do it. C# does not have a between operator I believe.
You could always cheat and write an extension method like I do:
Then you can do this ;-)