lambda今天和明天的条款
我有一个LINQ查询,可与各种子句添加。 但是我也想退还单身人士参加今天或明天的活动。
Dances_Moderated = Dances_Moderated
.Where(x => x.SingleDate == DateTime.Today)
&& (x => x.SingleDate == DateTime.Today.AddDays(1))
.ToList();
&& 后的代码以红色下划线,错误说:
CS0023:操作员'。不能应用于“ lambda表达式”类型的操作数
I have a Linq query that works with various Where clause additions.
But I also want to return the SingleDate for an Event where it is today or tomorrow.
Dances_Moderated = Dances_Moderated
.Where(x => x.SingleDate == DateTime.Today)
&& (x => x.SingleDate == DateTime.Today.AddDays(1))
.ToList();
The code after the && is underlined in red, and the error says:
CS0023: Operator '.' cannot be applied to operand of type 'lambda expression'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
||
(或),而不是&&
( and ):x 。我添加了
.date
为了处于安全方面:当我们使用==
时,我们只想比较日期,而不是时间部分。You should use
||
(or) instead of&&
(and):x.SingleDate.Date
should be either Today or tomorrow. I've added.Date
in order to be on the safe side of the road: when we use==
we want to compare dates only, not time parts.您的代码中有几个错误:
第一:语法错误,
第二:业务错误。您的单身永远不会等于datetime..now。您应该使用更大和更少的操作员来做到这一点。
您的代码应该是这样:
You have couple of errors in your code:
First: Syntax error,
Second: Business error. Your SingleDate never gonna equal to datetime.now. You should use greater and less operator to do that.
Your code should be like this: