【问题标题】:Multiple condition in LINQ where clauseLINQ where 子句中的多个条件
【发布时间】:2016-11-29 06:12:13
【问题描述】:

我是 LINQ 世界的新手。我正在尝试按如下方式计算总和-

 var newSum = (from c in db.ExecutionDetails 
               join camp in db.CampaignDetailsPerExecutions 
               on c.SmsId equals camp.SmsId 
               where c.AmoCode == 5 
               && c.DateTime between date1 and date2  //error
               select camp.Poster).Sum();

&& where 子句中的运算符给出错误(红色卷曲下划线)。

【问题讨论】:

  • @IanNewson,我试过了。它给出了“查询正文必须以选择子句或组关闭结尾”。

标签: c# .net linq date where-clause


【解决方案1】:

我希望你这样做是错误的,你必须像这样修改 where 子句:

where c.AmoCode == 5 && 
     (c.DateTime >= date1 && c.DateTime <= date2)

如果要排除日期的上限和下限,则意味着从比较中删除 = 符号。

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 2015-09-29
    相关资源
    最近更新 更多