Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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#Linq_C#_Linq_Datetime - Fatal编程技术网

带日期时间字段的C#Linq

带日期时间字段的C#Linq,c#,linq,datetime,C#,Linq,Datetime,我想从我的sql数据库中获取数据,这些数据都来自指定的日期或从今天开始的日期。只是今天的所有数据。字段“ZeitTempel”来自日期时间类型。我寻找了一些解决方案,发现: var query = from z in context.zeichnungs where EntityFunctions.TruncateTime(z.Zeitstempel) == EntityFunctions.TruncateTime(DateTime.Now) select z; 我的问

我想从我的sql数据库中获取数据,这些数据都来自指定的日期或从今天开始的日期。只是今天的所有数据。字段“ZeitTempel”来自日期时间类型。我寻找了一些解决方案,发现:

var query =
    from z in context.zeichnungs
    where EntityFunctions.TruncateTime(z.Zeitstempel) == EntityFunctions.TruncateTime(DateTime.Now)
    select z;
我的问题是,当我像这样使用查询数据时

foreach (zeichnung zeichnung in query)
{
    if (!zeichnung.Status.Equals("gelöscht"))
    {
        zeichnungInDB = new ZeichnungInDB(zeichnung.Zeichnungsnummer, zeichnung.Index, zeichnung.Volante_Index, zeichnung.Dateiendung, zeichnung.Dokumententyp);
        zeichnungen.Add(zeichnungInDB);
    }
}
我有一个EntityCommandExecutionException。
有人知道我的问题吗?

不要对
日期时间生成的内存值使用
EntityFunctions.TruncateTime
。现在
。改用:

使用DateTime.Today。 DateTime.Today表示时间部分设置为00:00:00的当前系统日期

DateTime。现在表示当前系统日期和时间

要了解有关DateTime的更多信息,请执行以下操作:

使用DateTime.Today。DateTime。今天表示当前系统日期,时间部分设置为00:00:00和DateTime。现在表示当前系统日期和时间感谢您的快速响应。但遗憾的是,我也犯了同样的错误。你有没有其他想法,我可以检查错误是什么?@Only3lue你可以尝试一些非常简单的方法-选择
EntityFunctions.TruncateTime(z.Zeitstempel)
值,并将结果转换为列表以查看这一基本步骤是否有效?@Only3lue如果你不能单独选择
EntityFunctions.TruncateTime(z.Zeitstempel)
字段,问题在于数据库中
Zeitstempel
字段的类型或内容。嗯,这很奇怪,因为我在程序中读取Zeitstempel字段时使用了其他Linq选项。但我完全可以进去。不知道这是什么…可能是因为数据库中的排序规则字段为空,所以这是一个错误吗?
var query =
    from z in context.zeichnungs
    where EntityFunctions.TruncateTime(z.Zeitstempel) == DateTime.Today
    select z;