Linq to sql 使用GROUP BY和COUNT with Date将LINQ转换为SQL(转换问题)

Linq to sql 使用GROUP BY和COUNT with Date将LINQ转换为SQL(转换问题),linq-to-sql,Linq To Sql,我读过,但不完全是我想要的。 我的问题是我不想这样做: SELECT CONVERT(varchar(10), m.CreateDate, 103) as [Date] , count(*) as [Count] FROM MEMBERS as m WHERE m.CreateDate >= '24/01/2008' and m.CreateDate <= '26/06/2009' Group by CONVERT(varchar(10), m.CreateDate, 103)

我读过,但不完全是我想要的。 我的问题是我不想这样做:

SELECT CONVERT(varchar(10), m.CreateDate, 103) as [Date] , count(*) as [Count] FROM MEMBERS as m
WHERE m.CreateDate >= '24/01/2008' and m.CreateDate <= '26/06/2009' 
Group by CONVERT(varchar(10), m.CreateDate, 103)
我正在这样做:

From m In Me.Members _
Where m.CreateDate >= "22/02/2008" And m.CreateDate <= "22/05/2009" _
Group m By m.CreateDate Into g = Group _
Select New With {CreateDate, .Count = g.Count()}
所以我知道差异是转换部分。那么,在LINQ中如何将Date或Datetime转换为SmallDate或类似的东西呢

谢谢

试试这个:

From m In Me.Members _
Where m.CreateDate.Date >= new DateTime( 2009, 2, 22 ) And m.CreateDate.Date <= new DateTime( 2009, 5, 22) _
Group m By day = m.CreateDate.Date Into g = Group _
Select New With { .Date = day.ToString( "dd/MM/yyyy" ), .Count = g.Count()}
来自m In Me.Members_
其中m.CreateDate.Date>=新日期时间(2009,2,22)和m.CreateDate.Date请尝试以下操作:

From m In Me.Members _
Where m.CreateDate.Date >= new DateTime( 2009, 2, 22 ) And m.CreateDate.Date <= new DateTime( 2009, 5, 22) _
Group m By day = m.CreateDate.Date Into g = Group _
Select New With { .Date = day.ToString( "dd/MM/yyyy" ), .Count = g.Count()}
来自m In Me.Members_

其中m.CreateDate.Date>=新日期时间(2009,2,22)和m.CreateDate.Date返回的“日期”不是“日期”的成员。但是你的想法是对的,我不确定它是否可以为空(见我的评论)。另外,要注意结束日期的比较。根据您的书写方式,我认为它不会包括2009年5月22日的项目,因为这些项目都在该日期的午夜之后。它返回的“日期”不是“日期”的成员。但是你的想法是对的,我不确定它是否可以为空(见我的评论)。另外,要注意结束日期的比较。你的方式是写我不认为它将包括项目从22/5/2009,因为他们都是在午夜后的日期。
      Date          Count
24/02/2009 00:00:00  1
24/02/2009 07:07:10  1
24/02/2009 12:24:10  1
25/02/2009 03:43:05  1 
25/02/2009 03:48:36  1 
25/02/2009 04:25:11  1 
26/02/2009 01:51:24  1 
26/02/2009 09:54:55  1 
26/02/2009 09:55:31  1 
02/03/2009 05:29:22  1 
02/03/2009 05:45:50  1 
02/03/2009 06:15:31  1 
02/03/2009 06:59:07  1
From m In Me.Members _
Where m.CreateDate.Date >= new DateTime( 2009, 2, 22 ) And m.CreateDate.Date <= new DateTime( 2009, 5, 22) _
Group m By day = m.CreateDate.Date Into g = Group _
Select New With { .Date = day.ToString( "dd/MM/yyyy" ), .Count = g.Count()}