gpt4 book ai didi

c# - 使用linq-sql从指定日期和时间范围内的数据库中获取数据

转载 作者:行者123 更新时间:2023-11-30 21:23:44 24 4
gpt4 key购买 nike

我有一个表,其中有两个单独的日期和时间列 (SQL Server 2008)。

我试图在我的 asp.net MVC (C#) 应用程序中获取当前时间之前 1 分钟和当前时间之后 1 分钟之间的数据。

我尝试将 where 条件用作:

ce.Start_Date.Add(ce.Start_Time) >= _currDateTime.AddMinutes(-1) && 
ce.Start_Date.Add(ce.Start_Time) <= _currDateTime.AddMinutes(1)

但是从上面的where条件来看,会报错:

The datepart millisecond is not supported by 
date function dateadd for data type date.

我该如何纠正/纠正这个错误?

最佳答案

不要在 where 子句中添加分钟,而是尝试这样的事情:

for ce in data
let start = _currDateTime.AddMinutes(-1)
let end = _currDateTime.AddMinutes(1)
where ce.Start_Date.Add(ce.Start_Time) >= start &&
ce.Start_Date.Add(ce.Start_Time) <= end
select ce

LINQ to SQL 正在尝试将您的 where 子句转换为有效的 T-SQL(使用 T-SQL's dateadd function ),但在执行过程中遇到了问题。

关于c# - 使用linq-sql从指定日期和时间范围内的数据库中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1594275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com