问题描述
我在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
推荐答案
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
这篇关于如何从可为空的日期时间列LINQ中删除时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!