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

Nir*_*ole 3 c# linq asp.net-mvc-5

您好我正在尝试编写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(); 
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.谢谢.

Yuv*_*hap 13

使用DbFunctions.TruncateTime方法:

created = DbFunctions.TruncateTime(c.createdDate)
Run Code Online (Sandbox Code Playgroud)

根据文件:

当用作LINQ to Entities查询的一部分时,此方法调用规范的TruncateTime EDM函数以返回给定日期并清除时间部分.