将SELECT ROW_NUMBER()OVER转换为linq

时间:2016-12-22 11:13:57

标签: c# sql sql-server linq

如何将此请求转换为 Linq 以从表中获取日期和行号?

SELECT ROW_NUMBER() OVER (ORDER BY Date) AS Row, 
       Date, 
       WebUrlReferer
 FROM [Cnx].[dbo].[Action]

1 个答案:

答案 0 :(得分:0)

var query = youContext.Action
            .Select((x, i) => new
                              {
                                  Row = i,
                                  Date = x.Date,
                                  WebUrlReferer = x.WebUrlReferer
                              }) 
            .OrderBy(x => x.Date);