Group by Week of year (Week number) in Linq to SQL

后端 未结 6 2027
旧时难觅i
旧时难觅i 2021-01-05 17:20

In regular SQL i could do something like

SELECT * From T GROUP BY DATEPART(wk, T.Date)

How can i do that in Linq to SQL ?

The follo

6条回答
  •  醉酒成梦
    2021-01-05 18:16

    This works correctly.

    from F in DB.T group F by F.Date.DayOfYear / 7;
    

    You were specifying the group by incorrectly. The result of this code be a collection of objects. Each object will have a Key property which will be what you grouped by (in this case the result of F.Date.DayOfYear / 7. Each object will be a collection of objects from T that met the group condition.

提交回复
热议问题