Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF Core sum date,timespan在where语句中_C#_Ef Core 3.1 - Fatal编程技术网

C# EF Core sum date,timespan在where语句中

C# EF Core sum date,timespan在where语句中,c#,ef-core-3.1,C#,Ef Core 3.1,在EF Core 3.1中,我有以下模型 public class Advertisement { public int Id { get; set; } public string Title { get; set; } public DateTimeOffset? EndPeriod { get; set; } public TimeSpan Duration { get; set; } } 我有一个简单的要求,用LINQ检查广告结束时间是否小于当前日期

在EF Core 3.1中,我有以下模型

 public class Advertisement
{
    public int Id { get; set; }
    public string Title { get; set; }
    public DateTimeOffset? EndPeriod { get; set; }
    public TimeSpan Duration { get; set; } 
}
我有一个简单的要求,用LINQ检查广告结束时间是否小于当前日期加上持续时间

我试过了

ads.Where(a => EF.Functions
               .DateDiffMinute(a.EndPeriod, DateTimeOffset.Now.Add(a.Duration)) <= 0)
ads.Where(a=>EF.Functions

.DateDiffMinute(a.EndPeriod,DateTimeOffset.Now.Add(a.Duration))似乎无法翻译此表达式
DateTimeOffset.Now.Add(a.Duration)

尝试使用类似以下内容:

ads
  .Select(a => new
  {
     ...
     a.EndPeriod,
     Period = DateTimeOffset.Now.Add(a.Duration)
  })
  .Where(a => EF.Functions.DateDiffMinute(a.EndPeriod, a.Period) <= 0)
广告
.选择(a=>新建
{
...
a、 期末,
Period=DateTimeOffset.Now.Add(a.Duration)
})

.Where(a=>EF.Functions.DateDiffMinute(a.EndPeriod,a.Period)这不是EF core 5.0的一个功能吗?对不起,我错过了。我写的是相同的方法。删除我的答案,因为我们都以相同的方式回答。If
DateTimeOffset.Now.Add(a.Duration)
无法翻译,将其放入中间投影有何帮助?它仍然无法翻译。