gpt4 book ai didi

c# - 如何在 linq 查询中从日期截断时间部分?

转载 作者:行者123 更新时间:2023-11-30 13:14:34 24 4
gpt4 key购买 nike

您好,我正在尝试编写 linq 查询以从 Sql 表中获取一些详细信息。我已经创建了列并存储了日期和时间。回来的时候我想省略时间部分。我可以知道这可能吗?

  List<returnObject> obj = new List<returnObject>();
obj = (from c in objectDB.NCT_Project
join user in objectDB.NCT_UserRegistration on c.adminUserId equals user.User_Id
where c.adminUserId == userId
select new returnObject
{
id = c.project_Id,
key = c.key,
created = c.createdDate //currently returns datetime
}).ToList();

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

使用DbFunctions.TruncateTime方法:

created = DbFunctions.TruncateTime(c.createdDate)

根据文档:

When used as part of a LINQ to Entities query, this method invokes thecanonical TruncateTime EDM function to return the given date with thetime portion cleared.

关于c# - 如何在 linq 查询中从日期截断时间部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43912381/

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