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

后端 未结 6 2024
旧时难觅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 17:53

    You can use the SqlFunctions.DatePart method from the System.Data.Entity.SqlServer namespace.

    // Return the week number
    From F In DB.T Group R By SqlFunctions.DatePart("week", F.Date)
    

提交回复
热议问题