如何从可为空的日期时间列LINQ中删除时间
我在LINQ查询中遇到问题,请帮助我.
使用select和string.join
通过group by join datetime列进行LINQ查询
这样显示的datetime值
使用string.Join(Environment.NewLine,来自子查询的l.DatetimeColumn)
21/03/2017 11:05:04
01/05/2017 12:24:55
08/05/2017 13:34:12
如果我使用
EntityFunctions.TruncateTime
像这样显示
21/03/2017 00:00:00
01/05/2017 00:00:00
我尝试过的事情:
在LINQ查询中遇到问题,请帮助我
Hi,
I am getting problem in LINQ query please help me.
LINQ query with group by join datetime column using select and string.join
datetime value shown like this
using string.Join(Environment.NewLine, l.DatetimeColumn from subquery)
21/03/2017 11:05:04
01/05/2017 12:24:55
08/05/2017 13:34:12
if i use
EntityFunctions.TruncateTime
it shown like this
21/03/2017 00:00:00
01/05/2017 00:00:00
What I have tried:
Getting problem in LINQ query please help me
如果我正确理解您的意思,则只想返回日期部分(忽略时间部分).为 F-ES Sitecore [EntityFunctions.TruncateTime方法(System.Data.Objects) [ ^ ]截断时间,但不会将其删除.要返回日期字符串列表,您必须使用类似于以下内容的内容:
If i understand you correctly, you want to return only date part (ignore time part). As F-ES Sitecore[^] mentioned in the comment to the question, EntityFunctions.TruncateTime Method (System.Data.Objects)[^] truncates the time but doesn''t remove it. To return a list of date-strings, you have to use something similar to:
var result = string.Join(",", db_context
.Where(x => x!=null) //get non null values
.ToList() //<=this might be needed within EF
.Select(x => x.Value.ToString("dd/MM/yyyy", provider))
.Distinct()); //get non-duplicates
结果:
Result:
21/03/2017,01/05/2017,08/05/2017,21/05/2017